[RESOLVED] can operator() be a member function template
Hello all,
I want to overload operator() of a class with a template function like below
//---------------------------
class A {
public:
template< int type >
void
operator()() {
int i;
}
};
int main() {
A an_a;
an_a()<100>;
}
//--------------------
but i get the following errors (gcc 4.3.3):
file.cpp: In function ‘int main()’:
file.cpp:14: error: no match for call to ‘(A) ()’
file.cpp:14: error: expected primary-expression before ‘;’ token
what is the problem?
Re: can operator() be a member function template
You have to use the full operator name to invoke the method. It fails because the < operator has a higher precendence than the template argument bracket and the compiler tries to evaluate (anA < 100) > (), which is no valid syntax.
Code:
// works:
anA.operator()<100>();
// fails:
anA<100>();
Re: [RESOLVED] can operator() be a member function template