I am writing a general Vector class and I want a Vector3 class to inherit from Vector. Vector's data can be of any length, Vector3's data is of length 3. So I want to make a different constructor for Vector3 which accesses the Vector's data and length. For this question I simplified the code.
#include <iostream>
template <typename T>
class A {
protected:
T value;
public:
A()
: value(0)
{};
A(T value)
: value(value)
{};
~A ()
{};
T get_value()
{
return value;
}
};
template <typename T>
class B : public A<T> {
public:
B()
: A<T>(3)
{};
T test()
{
return value; // error: 'value' was not declared in this scope
}
};
As I said I want to access 'value' in the child class 'B', however I get the error notification
error: 'value' was not declared in this scope
However according to the c++ website (http://www.cplusplus.com/doc/tutorial/polymorphism/) I should be able to access 'value'.
Why is this, and more important, how do I solve this?