What am I missin here ? (template functor question)

Discussion in 'C++' started by Bit Byte, Mar 5, 2007.

  1. Bit Byte

    Bit Byte Guest

    I have the folowing functor declaration:


    template < class T, typename ReturnType, typename Parameter >
    class Functor : public NonCopyable
    {
    public:
    typedef ReturnType (T::*Method)(Parameter);

    inline Functor(T* classInstance, Method method)
    :m_instance(classInstance), m_method(method) {}

    inline ReturnType operator()(Parameter parameter) { return
    (m_instance->*m_method)(parameter); }

    inline ReturnType execute(Parameter parameter) { return
    operator()(parameter); };

    private:
    T* m_instance;
    Method m_method;
    };


    The compiler complains as ff:

    Error 2 error C2825: 'T': must be a class or namespace when followed by '::'
    Error 3 error C2825: 'T': must be a class or namespace when followed by '::'
    Error 4 error C2645: no qualified name for pointer to member (found ':: *')
    Error 5 error C2143: syntax error : missing ')' before '`global namespace''
    Error 6 error C2143: syntax error : missing ';' before '`global namespace''
    Error 7 error C2146: syntax error : missing ';' before identifier 'Method'

    yada yada ....

    ???
    Bit Byte, Mar 5, 2007
    #1
    1. Advertising

  2. Bit Byte

    mlimber Guest

    On Mar 5, 9:34 am, Bit Byte <> wrote:
    > I have the folowing functor declaration:
    >
    > template < class T, typename ReturnType, typename Parameter >
    > class Functor : public NonCopyable
    > {
    > public:
    > typedef ReturnType (T::*Method)(Parameter);
    >
    > inline Functor(T* classInstance, Method method)
    > :m_instance(classInstance), m_method(method) {}
    >
    > inline ReturnType operator()(Parameter parameter) { return
    > (m_instance->*m_method)(parameter); }
    >
    > inline ReturnType execute(Parameter parameter) { return
    > operator()(parameter); };
    >
    > private:
    > T* m_instance;
    > Method m_method;
    >
    > };
    >
    > The compiler complains as ff:
    >
    > Error 2 error C2825: 'T': must be a class or namespace when followed by '::'
    > Error 3 error C2825: 'T': must be a class or namespace when followed by '::'
    > Error 4 error C2645: no qualified name for pointer to member (found ':: *')
    > Error 5 error C2143: syntax error : missing ')' before '`global namespace''
    > Error 6 error C2143: syntax error : missing ';' before '`global namespace''
    > Error 7 error C2146: syntax error : missing ';' before identifier 'Method'
    >
    > yada yada ....
    >
    > ???


    Please see http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.8
    on how to post code that doesn't work correctly. If I delete the
    missing NonCopyable class and add this:

    struct A
    {
    void Foo( int ) {}
    };

    int main()
    {
    A a;
    Functor<A,void,int> f( &a, &A::Foo );;
    f( 1 );
    return 0;
    }

    It works fine for me with VC++ 7.1 and 8 and Comeau.

    Cheers! --M
    mlimber, Mar 5, 2007
    #2
    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. Chandra Shekhar Kumar

    functor object in template class

    Chandra Shekhar Kumar, Jun 24, 2003, in forum: C++
    Replies:
    5
    Views:
    1,271
    porschberg
    Jun 26, 2003
  2. CoolPint
    Replies:
    3
    Views:
    709
    tom_usenet
    Dec 29, 2003
  3. jack
    Replies:
    3
    Views:
    399
    Victor Bazarov
    Feb 28, 2004
  4. Replies:
    8
    Views:
    404
  5. Les Caudle
    Replies:
    3
    Views:
    2,312
    Steven Cheng[MSFT]
    Sep 3, 2007
Loading...

Share This Page