member function specialization

This is a discussion on member function specialization within the C++ Programming forums, part of the General Programming Boards category; Hi, I have a problem with templated member function ( partial? ) specialization. .h: Code: class a : public b< ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    11

    member function specialization

    Hi,

    I have a problem with templated member function ( partial? ) specialization.

    .h:
    Code:
    class a : public b< int >
    {
    public:
        template< class DATA >
        void foo( int id,DATA pack )
        {
             ...
        }
    };
    .cpp :
    Code:
    template<>
    void a::foo< int >( int id,int pack )
    {
        ...
    }
    With this I get the multiple definition of ... error.

    Anyone knows how to implement this correctly?

    Regards,
    Domen

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,160
    You cannot specialize a function template -- you overload it instead. Just write:

    Code:
    void a::foo( int id,int pack )

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    11
    Works now. Thanks for the answer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-19-2008, 12:06 AM
  2. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  5. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM

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