struct Test
{
template <class T>
void print(T& t)
{
t.print();
}
};
struct A
{
void print() {printf( "A");}
};
struct B
{
void print() {printf( "B");}
};
void test_it()
{
A a;
B b;
Test t;
t.print(a);
t.print(b);
}
This compiles fine.
struct Test
{
template <class T>
void print(T& t)
{
t.print();
}
};
void test_it()
{
struct A
{
void print() {printf( "A");}
};
struct B
{
void print() {printf( "B");}
};
A a;
B b;
Test t;
t.print(a);
t.print(b);
}
This fails with error :
no matching function for call to ‘Test::print(test_it()::A&)’
Can anyone explain me why this happen ?
Thanks!!!
In your second example,
AandBare local types, which can’t be used as template type arguments in C++03 as per §14.3.1/2: