0

I am trying to create a template so that I can have a function pointer (for a callback function) that accepts both a Class as a base for member functions as well as as having a way to have globally defined functions.

At the moment I have

template <class c> struct Callback { typedef void(c::*callback)(void); }; 

Which works and will allow me to use Callback::callback as a type

However when I try and add a specific implementation such as:

class VOIDCLASS { void * void_ptr; }; // Callback template declaration as above here template <VOIDCLASS> struct Callback { typedef void(*callback)(void); }; 

I get a compiler error : error C3855: 'Callback': template parameter 'c' is incompatible with the declaration This is using Visual Studio 2013 with a platform tool-set of v110(VS2012) and Windows 8.1

2 Answers 2

2

An explicit specialization is written like this:

template<> struct Callback<VOIDCLASS> { typedef void(*callback)(void); }; 
Sign up to request clarification or add additional context in comments.

Comments

1

I think you meant:

template <> struct Callback<VOIDCLASS> { typedef void(*callback)(void); }; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.