Declaring a Static Member of a Function Pointer

Discussion in 'C++' started by Brandon, Aug 8, 2004.

  1. Brandon

    Brandon Guest

    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;
    Brandon, Aug 8, 2004
    #1
    1. Advertising

  2. On 7 Aug 2004 19:44:15 -0700, Brandon <> 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
    John Harrison, Aug 8, 2004
    #2
    1. Advertising

  3. Brandon

    Arne Adams Guest

    (Brandon) wrote in message news:<>...
    > 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
    Arne Adams, Aug 8, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. 0to60
    Replies:
    4
    Views:
    503
    jeffc
    Nov 21, 2003
  2. Fraser Ross
    Replies:
    4
    Views:
    1,026
    Fraser Ross
    Aug 14, 2004
  3. dolphin
    Replies:
    3
    Views:
    1,324
    Pete Becker
    Dec 5, 2007
  4. pembed2012
    Replies:
    1
    Views:
    410
    James Kuyper
    Feb 27, 2012
  5. somenath
    Replies:
    2
    Views:
    146
    somenath
    Aug 29, 2013
Loading...

Share This Page