Thanks CornedBee!
Two more comments,
1.
Originally Posted by
CornedBee
2) Yep. I comment out the call and get the same error.
Do you mean the following code compile error in your side? I can compile fine. I am using Visual Studio 2008. In the following code, only class is instantised, no member functions are called.
Code:
#include <iostream>
using namespace std;
template <typename T> struct Base {
public:
Base (int _i): i (_i)
{
}
int i;
};
template <typename T> struct Derived : public Base <T> {
public:
Derived (int _i) : Base<T> (_i)
{
}
int get_i() { return i; }
};
int main()
{
Derived<int> d (200);
// cout << d.get_i() << endl; // output 200
return 0;
}
2.
Originally Posted by
CornedBee
3)
These comments.
Do you mean you can not compile if we make base class non-template? I am confused. It could compile in my envionrment. Are you using the code below?
Code:
#include <iostream>
using namespace std;
/*template <typename T> */ struct Base {
public:
Base (int _i): i (_i)
{
}
int i;
};
template <typename T> struct Derived : public Base/* <T>*/ {
public:
Derived (int _i) : Base/*<T>*/ (_i)
{
}
int get_i() { return i; }
};
int main()
{
Derived<int> d (200);
cout << d.get_i() << endl; // output 200
return 0;
}
regards,
George