Declaring a Static Member of a Function Pointer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brandon

    Declaring a Static Member of a Function Pointer

    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 ;
  • John Harrison

    #2
    Re: Declaring a Static Member of a Function Pointer

    On 7 Aug 2004 19:44:15 -0700, Brandon <bcr07548@creig hton.edu> wrote:
    [color=blue]
    >
    > 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 ;[/color]

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

    template <class T>
    typename XYZ<T>::funcPtr XYZ<T>::myCallb ack;

    and make sure that goes in a header file.

    john

    Comment

    • Arne Adams

      #3
      Re: Declaring a Static Member of a Function Pointer

      bcr07548@creigh ton.edu (Brandon) wrote in message news:<24f6b708. 0408071844.75e6 c4ab@posting.go ogle.com>...[color=blue]
      > 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 ;[/color]

      try:

      template<class T> typename XYZ<T>::funcPtr XYZ<T>::myCallb ack;

      Arne

      Comment

      Working...