|
-
January 8th, 2010, 12:57 AM
#1
[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?
-
January 8th, 2010, 03:30 AM
#2
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>();
Last edited by GNiewerth; January 8th, 2010 at 03:33 AM.
- Guido
-
January 10th, 2010, 04:37 AM
#3
Re: [RESOLVED] can operator() be a member function template
Thanks for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|