J
Jim West
Can someone please explain to me why the following compiles:
class A {
public:
int d;
};
class B : public A {
public:
int e;
void f() { d = e; };
};
but if I make A and B templates it gives an error:
template <typename T>
class A {
public:
T d;
};
template <typename T>
class B : public A<T> {
public:
int e;
void f() { d = e; }; // error: identifier "d" is undefined
};
This occurs with GNU G++ and Intel ICC. Obviously I am missing a subtlety
of templates and/or inheritance. (I figured out that changing the line in
question to
void f() { A<T>::d = e; };
corrects the error, but I want understand why it is an error in the first
place.)
class A {
public:
int d;
};
class B : public A {
public:
int e;
void f() { d = e; };
};
but if I make A and B templates it gives an error:
template <typename T>
class A {
public:
T d;
};
template <typename T>
class B : public A<T> {
public:
int e;
void f() { d = e; }; // error: identifier "d" is undefined
};
This occurs with GNU G++ and Intel ICC. Obviously I am missing a subtlety
of templates and/or inheritance. (I figured out that changing the line in
question to
void f() { A<T>::d = e; };
corrects the error, but I want understand why it is an error in the first
place.)