Taking address of member template function.

Discussion in 'C++' started by Stuart Redmann, Feb 13, 2007.

  1. Hello newsgroup,

    I try to take the address of a member template function, but I can't
    succeed. My copy of Bjarne Stroupstrup says nothing against this, so I
    guess that what I want to achive is not beyond the possibilities of C++,
    but beyond the abilities of my compiler (Visual C++ 6.0). Following code
    won't compile (error C2039: 'SomeFunc' : Is no element of '`global
    namespace''). Any suggestions would be highly appreciated.

    class TestClass
    {
    public:
    template<int t_ID>
    void SomeFunc ()
    {}
    };

    void (TestClass::*pFuncPtr) () = TestClass<0>::SomeFunc;

    Thanks in advance,
    Stuart
     
    Stuart Redmann, Feb 13, 2007
    #1
    1. Advertising

  2. On Feb 13, 10:16 am, Stuart Redmann <> wrote:

    > I try to take the address of a member template function, but I can't
    > succeed. My copy of Bjarne Stroupstrup says nothing against this, so I
    > guess that what I want to achive is not beyond the possibilities of C++,
    > but beyond the abilities of my compiler (Visual C++ 6.0). Following code
    > won't compile (error C2039: 'SomeFunc' : Is no element of '`global
    > namespace''). Any suggestions would be highly appreciated.
    >
    > class TestClass
    > {
    > public:
    > template<int t_ID>
    > void SomeFunc ()
    > {}
    >
    > };
    >
    > void (TestClass::*pFuncPtr) () = TestClass<0>::SomeFunc;


    Two suggestions:

    1. Your syntax is wrong. Change the last line to:

    void (TestClass::*pFuncPtr) () = &TestClass::SomeFunc<0>;

    2. Get a new compiler - Visual C++ 6.0 is horribly out of date.

    Best regards,

    Tom
     
    Thomas Tutone, Feb 13, 2007
    #2
    1. Advertising

  3. Thomas Tutone wrote:

    > On Feb 13, 10:16 am, Stuart Redmann <> wrote:
    >>I try to take the address of a member template function, but I can't
    >>succeed. My copy of Bjarne Stroupstrup says nothing against this, so I
    >>guess that what I want to achive is not beyond the possibilities of C++,
    >>but beyond the abilities of my compiler (Visual C++ 6.0). Following code
    >>won't compile (error C2039: 'SomeFunc' : Is no element of '`global
    >>namespace''). Any suggestions would be highly appreciated.
    >>
    >>class TestClass
    >>{
    >>public:
    >> template<int t_ID>
    >> void SomeFunc ()
    >> {}
    >>
    >>};
    >>
    >>void (TestClass::*pFuncPtr) () = TestClass<0>::SomeFunc;

    >
    >
    > Two suggestions:
    >
    > 1. Your syntax is wrong. Change the last line to:
    >
    > void (TestClass::*pFuncPtr) () = &TestClass::SomeFunc<0>;


    That is what I was afraid of: With this syntax I get
    fatal error C1001: INTERNAL COMPILER- ERROR

    > 2. Get a new compiler - Visual C++ 6.0 is horribly out of date.


    I will. Honestly.

    Thanks,
    Stuart
     
    Stuart Redmann, Feb 13, 2007
    #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. Domenico Andreoli

    taking address of a template method

    Domenico Andreoli, Aug 12, 2003, in forum: C++
    Replies:
    2
    Views:
    296
    Domenico Andreoli
    Aug 12, 2003
  2. Brian Riis
    Replies:
    3
    Views:
    509
    Brian Riis
    Nov 2, 2004
  3. Replies:
    1
    Views:
    481
    Victor Bazarov
    Jul 20, 2005
  4. Peng Yu
    Replies:
    3
    Views:
    802
    Thomas J. Gritzan
    Oct 26, 2008
  5. Jim Cain
    Replies:
    1
    Views:
    226
    Yukihiro Matsumoto
    Jul 18, 2003
Loading...

Share This Page