|
-
March 16th, 2010, 12:41 AM
#1
[RESOLVED] static member functions in class templates
Hi,
Can anybody help me why this code does not compile (gcc 4.2.4)
what does the error "invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator<’" means?
--------------------------------------------------------------------------------------------------
struct foo {
template< int N >
static void increase( int& i );
};
template< int N >
void foo::increase( int& i )
{i += N;}
template< class T >
void f(){
int i=0;
T::increase<1>(i);
}
int main(){
f<foo>();
}
--------------------------------------------------------------------------------------------------
Regards
-
March 16th, 2010, 03:39 AM
#2
Re: static member functions in class templates
the line "T::increase<1>(i);" should be "T::template increase<1>(i);".
being T::increase a dependent name the compiler thinks that the '<''s in "<1> " are < operators, thus the cryptic error. The template keyword is used to disambiguate these situations.
-
March 16th, 2010, 07:45 AM
#3
Re: static member functions in class templates
Tags for this Thread
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
|