CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2009
    Posts
    25

    [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

  2. #2
    Join Date
    Oct 2008
    Posts
    1,456

    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.

  3. #3
    Join Date
    Aug 2009
    Posts
    25

    Re: static member functions in class templates

    Thanks a lot! it worked

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
  •  





Click Here to Expand Forum to Full Width

Featured