什么是空类,为什么空类的大小是非零值?是否可以创建空类的对象 [英] what is an empty class,why the size of an empty class is non zero value?Is it possible to create objects to empty class

查看:100
本文介绍了什么是空类,为什么空类的大小是非零值?是否可以创建空类的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

课堂空白

{

};

int main()

{

空obj;

cout<< size(obj);

返回0;

}

解决方案

C ++语言的创建者Bjarne Stroustrup在这里回答了这个问题:为什么空类的大小不是零? [ ^ ]

class empty
{
};
int main()
{
empty obj;
cout<<size(obj);
return 0;
}

解决方案

Bjarne Stroustrup, the creator of the C++ language, answers the question here: Why is the size of an empty class not zero?[^]


这篇关于什么是空类,为什么空类的大小是非零值?是否可以创建空类的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆