I am trying to create my STL class, but I encounter some difficulties. I want to write a parent class inherited by two other class. And the parent class can get child class' type from template argument. Like the example code below.
When I compiled my codes with VS2013, I got some compile errors, C4430, C2868, C2602, C2146, C2039.
template<class Child>
class Base
{
public:
typedef typename Child::value_type value_type;
};
class Child_A : public Base<Child_A>
{
typedef double value_type;
};
class Child_B : public Base<Child_B>
{
typedef float value_type;
};
int main(){
Child_A ch_a;
Child_B ch_b;
}
I know that one way to make it work is putting children's value_type into parent's template field, but I don't like to do that. It will make my codes a little complex.
Is there any other method to solve this problem?
List of errors:
C2039:'value_type' : is not a member of 'Child_A'
C2602:'Base::value_type' is not a member of a base class of 'Base'
C2868:'Base::value_type' : illegal syntax for using-declaration; expected qualified-name