Using types defined in class

2019-08-30 09:51发布

问题:

What is the most convenient and clear way to define variables of type declared inside some complex class. For example:

template<class T1, class T2> 
class ClassA
{
    enum ENUM_A { A1, A2 };
    //constructor
    ClassA(const ENUM_A& x);
}

Then when you want to use this object somewhere else, you'll have to write long type definitions like:

ClassA<ClassT1, ClassT2>::ENUM_A var = ClassA<ClassT1, ClassT2>::A1;
ClassA<ClassT1, ClassT2> obj(var);

Is there any safe and convenient way to avoid such long declarations? (I've thought about typedef, but maybe it)

回答1:

The solutions have already been named: typedef (or using), and auto to skip naming the type entirely.



标签: c++ class types