Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Declaring a Static Member of a Function Pointer

Reply
Thread Tools

Declaring a Static Member of a Function Pointer

 
 
Brandon
Guest
Posts: n/a
 
      08-08-2004
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;
 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      08-08-2004
On 7 Aug 2004 19:44:15 -0700, Brandon <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Arne Adams
Guest
Posts: n/a
 
      08-08-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (Brandon) wrote in message news:<(E-Mail Removed). 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaring static function returning pointer to extern function pembed2012 C Programming 1 02-27-2012 08:21 PM
Can a static member function access non-static member? dolphin C++ 3 12-05-2007 12:39 PM
What is the correct grammar to make a function call by using static member data which is a pointer to a ordinary class member function? zaeminkr@gmail.com C++ 3 07-06-2007 12:50 PM
pointer to member function and pointer to constant member function Fraser Ross C++ 4 08-14-2004 06:00 PM
performance of static member function vs. instance member function 0to60 C++ 4 11-21-2003 05:25 PM



Advertisments