S
subramanian100in
#include <iostream>
using namespace std;
class Rec
{
public:
Rec(int arg = 10) : val(arg) { }
private:
int val;
};
template <class T> class Test
{
private:
T t;
public:
virtual void print( ) const { cout << t << endl; }
};
int main( )
{
Test<Rec> r;
return 0;
}
This program does not compile with g++ and also VC++2005 Express
Edition. However if the keyword 'virtual' is removed in
Test<T>:rint(), it compiles fine. Since 'print()' function is not at
all called in this program, why do I get compilation error if
Test<T>:rint() is virtual ?
Kindly explain.
Thanks
V.Subramanian
using namespace std;
class Rec
{
public:
Rec(int arg = 10) : val(arg) { }
private:
int val;
};
template <class T> class Test
{
private:
T t;
public:
virtual void print( ) const { cout << t << endl; }
};
int main( )
{
Test<Rec> r;
return 0;
}
This program does not compile with g++ and also VC++2005 Express
Edition. However if the keyword 'virtual' is removed in
Test<T>:rint(), it compiles fine. Since 'print()' function is not at
all called in this program, why do I get compilation error if
Test<T>:rint() is virtual ?
Kindly explain.
Thanks
V.Subramanian