Possible Duplicate:
Where and why do I have to put the “template” and “typename” keywords?
recently a piece of code confused me:
class A {
public:
typedef int SomeType;
void func(SomeType i);
SomeType func2();
};
void A::func(SomeType i) {
cout << "in A, value: " << i << endl;
}
SomeType A::func2() {
return 123;
}
int main() {
A a;
}
G++ 4.4 gives a compile error that it does not know the SomeType while compiling A::func2:
error: 'SomeType' does not name a type
But the same SomeType compiles well in A::func(SomeType i):
class A {
public:
typedef int SomeType;
void func(SomeType i);
};
void A::func(SomeType i) {
cout << "in A, value: " << i << endl;
}
Anyone can help me to understand this? It seems C++ treats unfair to argument types and return types?
gcc is right –
Before the
A::, you need to qualify the nested type withA::. So you need: