Using types defined in class

2019-08-30 09:40发布

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)

标签: c++ class types
1条回答
淡お忘
2楼-- · 2019-08-30 10:30

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

查看更多
登录 后发表回答