N
not.a
When I compile the following code:
//===================================================
template <typename T>
class Foo {
public:
T x,y,z;
};
template <typename T>
class Bar : public Foo<T> {
public:
Bar<T>& operator+=(const Bar<T>& rhs) {
x += rhs.x;
y += rhs.y;
z += rhs.z;
return *this;
}
};
//===================================================
I get the following message from gcc 3.4:
bad.cpp: In member function `Bar<T>& Bar<T>:perator+=(const Bar<T>&)':
bad.cpp:11: error: `x' undeclared (first use this function)
bad.cpp:11: error: (Each undeclared identifier is reported only once for
each function it appears in.)
bad.cpp:12: error: `y' undeclared (first use this function)
bad.cpp:13: error: `z' undeclared (first use this function)
If I "un-templatize" the classes Foo and Bar, the code compiles fine. Is
this a bug in gcc, or am I forgetting something about the way C++ handles
inheritance and templates?
Thanks,
Brett
//===================================================
template <typename T>
class Foo {
public:
T x,y,z;
};
template <typename T>
class Bar : public Foo<T> {
public:
Bar<T>& operator+=(const Bar<T>& rhs) {
x += rhs.x;
y += rhs.y;
z += rhs.z;
return *this;
}
};
//===================================================
I get the following message from gcc 3.4:
bad.cpp: In member function `Bar<T>& Bar<T>:perator+=(const Bar<T>&)':
bad.cpp:11: error: `x' undeclared (first use this function)
bad.cpp:11: error: (Each undeclared identifier is reported only once for
each function it appears in.)
bad.cpp:12: error: `y' undeclared (first use this function)
bad.cpp:13: error: `z' undeclared (first use this function)
If I "un-templatize" the classes Foo and Bar, the code compiles fine. Is
this a bug in gcc, or am I forgetting something about the way C++ handles
inheritance and templates?
Thanks,
Brett