1

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

IvanaGyro
  • 598
  • 7
  • 25
  • 1
    Please post the actual error text. We should not have to go look up those error messages to find out what is your issue. – NathanOliver Aug 01 '16 at 14:20
  • Thank everybody. I didn't find any answer after searching with wrong key words. I decide to solve my problem using the answer in the question, "C++ static polymorphism (CRTP) and using typedefs from derived classes". – IvanaGyro Aug 02 '16 at 08:37

0 Answers0