parse error in gcc but success in vc.net, call a non_template class's template member function from

Discussion in 'C++' started by ken, Jun 24, 2005.

  1. ken

    ken Guest

    the test code is :


    /////////////////////////////////////////////////////////////////
    #include <stdlib.h>
    #include <stdio.h>

    class CA
    {
    public:
    template <typename T>
    T Fun()
    {
    return T();
    }
    };
    template<>
    void CA::Fun<void>()
    {
    printf("in void\n");
    return;
    }

    template <typename T>
    class CB
    {
    public:
    int operator()(T a1=T())
    {
    printf("aaa\n");
    CA a;
    a.Fun<T>(); //error this line
    return 0;
    }
    };

    int main()
    {
    CB<int> b;
    b();
    return 0;
    }

    /////////////////////////////////////////////////////////////////

    the gcc 3.2.2 compiler report a error:
    testtemp.cpp: In member function `int CB<T>::eek:perator()(T)':
    testtemp.cpp:37: parse error before `;' token

    what's the matter? everything is right in the vc.net 7.1?
     
    ken, Jun 24, 2005
    #1
    1. Advertising

  2. On Fri, 24 Jun 2005 12:13:43 +0400, ken <> wrote:

    []

    > the gcc 3.2.2 compiler report a error:
    > testtemp.cpp: In member function `int CB<T>::eek:perator()(T)':
    > testtemp.cpp:37: parse error before `;' token
    >
    > what's the matter? everything is right in the vc.net 7.1?


    Looks like a gcc bug. The code compiles fine with g++ 3.4.3 and 4.0.0 and
    comeau online.

    --
    Maxim Yegorushkin
     
    Maxim Yegorushkin, Jun 24, 2005
    #2
    1. Advertising

  3. ken

    ken Guest

    it seems that I have to update my gcc :(
    thank you!
     
    ken, Jun 28, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page