I am trying to access a typedef element in a base class from a template of a derived class. In a template, the name of the template parameter matches the name typdef in the base class.
#include <iostream> using namespace std; class no { public : typedef int T; }; template<typename T> class no1 : public no { public : T obj; }; int main() { // your code goes here no1<string> o ; o.obj = "1"; return 0; } 14:24: error: invalid conversion from 'const char*' to 'no::T {aka int}' [-fpermissive] no1<string> o ; o.obj = "1";
In the above code, T obj is always of type int. How can I get obj to be from a template parameter, not a typdef declared in a base class?
thanks
source share