Possible Duplicate:
Two phase lookup – explanation needed
When I’m using a template class the compiler doesn’t show me errors/warning of missing #includes.
For example, If I have a class called “A” and it looks much or less like this :
template<class T>
class A {
void print() const {cout << "Hey I didn't use include for
iostream and It works just fine!!!";}
};
If I remove the template < class T > I get errors of the absence of <iostream >include.
Why the compiler doesn’t show these errors when I’m using template class ?
Just to point out, when I say It works I mean It doesn’t show me any compilation errors when I’m writing the class but only when I use it as opposed to a non-template class whereas the error shows immediately.
When you write template code, a huge bulk of the syntax checking happens only if and when you make an instance of this class, if it is never used, it is never checked.
To verify this, add this line at the end,
A<int>;More information at Two phase lookup – explanation needed as jrok points out.
Edit:
The linked posts bring up an interesting point, this does error out on gcc and clang even without an instantiation. I guess like myself, you are on MSVC++