GCC template issue

closed account (o1vk4iN6)
Not sure why this code generates a "no matching function for call to ‘test(main(int, char**)::A)", although the code runs compiles on MSVC, I was wondering if this is not standard ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

// main.cpp //

#include "template.h"

int main(int argc, char** main)
{

    class A {
    public:
        int operator()(){ return 32; }
    };

    A a;

    test( a );

}


// template.h //

template<class T>
int test( T & a )
{
    return a();
}



Although if A is moved out of main it compiles fine.
Last edited on
You need to declare the function test before main.
In C++98 local classes cannot be used as template parameters.
Depending on the version of GCC you are using, you may be able to compile that if you compile using the
-std=c++0x or -std=c++11 option.
Topic archived. No new replies allowed.