By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,918 Members | 2,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

Declaring a Static Member of a Function Pointer

P: n/a
In a templated class I wrote, there is a public typedef for a function
pointer. The class has an instance of the function pointer as a
private member. That pointer is declared as static so I need to
declare an instance of the pointer. So, I tried using the keyword
typename to declare the static member. I don't get any syntax errors
but the pointer's name shows up in an "undefined symbol" error at
compile time. Have a look at this example code and tell me if you can
stop an error.
template <class T>
class XYZ
{
public:
// Function pointer type
typedef int(*funcPtr)(T,T);
protected:
// Static function pointer
static funcPtr myCallback;
};

// XYZ's static function pointer declaration
typename XYZ<class T>::funcPtr XYZ<class T>::myCallback;
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 7 Aug 2004 19:44:15 -0700, Brandon <bc******@creighton.edu> wrote:

template <class T>
class XYZ
{
public:
// Function pointer type
typedef int(*funcPtr)(T,T);
protected:
// Static function pointer
static funcPtr myCallback;
};
// XYZ's static function pointer declaration
typename XYZ<class T>::funcPtr XYZ<class T>::myCallback;


You need to start any template declaration with the keyword template. I'd
try

template <class T>
typename XYZ<T>::funcPtr XYZ<T>::myCallback;

and make sure that goes in a header file.

john
Jul 22 '05 #2

P: n/a
bc******@creighton.edu (Brandon) wrote in message news:<24**************************@posting.google. com>...
compile time. Have a look at this example code and tell me if you can
stop an error.
template <class T>
class XYZ
{
public:
// Function pointer type
typedef int(*funcPtr)(T,T);
protected:
// Static function pointer
static funcPtr myCallback;
};

// XYZ's static function pointer declaration
typename XYZ<class T>::funcPtr XYZ<class T>::myCallback;


try:

template<class T> typename XYZ<T>::funcPtr XYZ<T>::myCallback;

Arne
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.