Help with function declaration error

This is a discussion on Help with function declaration error within the C++ Programming forums, part of the General Programming Boards category; Hello, I am working on a project for NACHOS (an OS for learning in C++) I am implementing a compare ...

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

    Question Help with function declaration error

    Hello,

    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:

    Code:
    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:

    Code:
    template <class T>
    int
    (*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
    Posts
    3,573
    You are trying to declare function pointers.

    A template function looks like this:
    Code:
    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, 02:17 AM
  2. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 11: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, 09:39 AM
  5. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 10:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21