consider the following program
#include <iostream>
using namespace std;
class Rec
{
public:
Rec(int arg = 10) : val(arg) { }
private:
int val;
};
template <class Tclass Test
{
private:
T t;
public:
void print( ) const { cout << t << endl; }
};
int main( )
{
Test<Recr;
// r.print( );
return 0;
}
This program compiles fine with g++ and VC++2005 Express Edition.
However if I remove the comment in the line
// r.print( ),
I get compilation error because operator<<( ) is not defined for Rec.
Why doesn't the compiler report this error when it tries to generate
(that is, instantiate) a class declaration for Test<Recitself?. Does
it mean the that the template member function definition is generated
only when the corresponding function is used(Test<T>::print( ) in this
case) ?
Kindly explain.
Thanks
V.Subramanian