What am I missin here ? (template functor question)

B

Bit Byte

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 ....

???
 
M

mlimber

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top