标签:
在看effective c++的时候,其中第二条边指出。尽量使用const ,enum代替define。在写程序的时候,需要入参为设备类型,第一反应是枚举一个设备类型,并以名字命名。但是有一个问题挺困惑的,类中的枚举到底是以什么形式存在的?枚举变量需不需要分配内存?
class test
{
public:
enum type{One,Two, Three};
private:
};
int _tmain(int argc, _TCHAR* argv[])
{
cout << sizeof(test)<<endl;
return 0;
}
class test
{
public:
enum type{One=2,Two, Three};
test():t(One)
{
}
type getT()
{
return t;
}
private:
type t;
};
int _tmain(int argc, _TCHAR* argv[])
{
test s;
cout << sizeof(test)<<endl;
cout<<s.getT()<<endl;
cout << test::Three<<endl;
return 0;
}
struct CEType
{
enum EType1 { e1, e2 };
enum EType2 { e1, e2 };
};
标签:
原文地址:http://www.cnblogs.com/chengkeke/p/5417368.html