Thread: Help with function declaration error

  1. #1
    Registered User
    Join Date
    Oct 2010
    San Francisco, CA

    Question Help with function declaration error


    I am working on a project for NACHOS (an OS for learning in C++)

    I am implementing a compare function based on a list template.

    The declaration for the compare function is in the header file and is as follows:

    int (*compare)(T x, T y);
    // function for sorting list elements

    I have written the function and my declaration in the .cc file as follows:

    template <class T>
    (*SortedList<T>::compare)(T x, T y)
    When I compile in Linux I get the following error:

    error : invalid function declaration

    I am a little stifled as to what I'm doing wrong... I am new to programming with templates in this capacity and some help would be great. Thank you very much!

    Best regards,

  2. #2
    The larch
    Join Date
    May 2006
    You are trying to declare function pointers.

    A template function looks like this:
    template <class T>
    int compare(const T& a, const T& b);
    and it can't be separated between a declaration in a header and an implementation in a source file (templates must be entirely in the header).
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  3. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM