I have this code structure:
- An abstract class A (it has a pure virtual method)
- A class template B that inherits from A
- A class template C that inherits from B
class A
{
protected:
int u;
int z;
public:
A(int uu,
int zz)
:u(uu),
z(zz)
{};
int get() const
{
return u;
};
virtual void blah() = 0;
};
template <class T>
class B : public A
{
protected:
std::vector<T> xxxx;
public:
B(int uu,
int zz,
int bbb)
:A(uu,
zz)
{
for(size_t i = 0; i < bbb; i ++)
xxxx[i] = 0;
};
virtual void blah()
{
u = u + 1;
};
};
template <class T>
class C : public B<T>
{
protected:
int qrqr;
public:
C(int uu,
int zz,
int bbb,
int qrqrqr)
:B<T>(uu,
zz,
bbb),
qrqr(qrqrqr)
{
};
virtual void blah()
{
u = u + qrqr;
};
};
When I compile I get this error:
error: 'u' was not declared in this scope
at line: u = u + qrqr;
Though u
is clearly an element of C because A is a base of C through B.
I read here: Class template inheritance C++ that the proper way to inherit from class template is either to specialize the class or to have the inherited class to be template and this is what I did here. The compiler doesn't seem to complain about it anyway. Could it be because A is an abstract class?
What did I do wrong?
Thanks!