使用类中定义的类型 [英] Using types defined in class
本文介绍了使用类中定义的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是最方便和清楚的方式来定义一些复杂类中声明的类型的变量。例如:
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);
有没有安全方便的方法避免这么长的声明? (我已经考虑了 typedef
,但也许是)
Is there any safe and convenient way to avoid such long declarations? (I've thought about typedef
, but maybe it)
推荐答案
解决方案已命名为 typedef
(或使用
)和自动
可以完全跳过命名类型。
The solutions have already been named: typedef
(or using
), and auto
to skip naming the type entirely.
这篇关于使用类中定义的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文