C ++类空类大小1个字节 [英] C++ class empty class size 1 byte
本文介绍了C ++类空类大小1个字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是C ++的新手,在C ++中发现了一个奇怪的特性。我看到一个空的大小是1个字节,我做了一些研究,发现是被做,因为每个对象必须有一个不同的地址。但我想知道被放置的1个字节的内容是什么。我知道它不持有这个指针,但它是一个虚拟字节或实际上有一些内容?
I am new to C++ and a found a peculiar feature in C++. I saw the size of an empty is 1 byte, I did some research and found out that is is done because every object must have a distinct address. But I want to know what is the content of that 1 byte that is placed. I know it does not hold the "this" pointer but is it a dummy byte or is there actually some content???
推荐答案
没有内容。
每个 class
或 struct
必须具有 sizeof
大于 0
,根据您的行为。这是标准的预期和授权。
Every class
or struct
must have its sizeof
greater than 0
, ergo your behavior. It's expected and mandated by the standard.
这篇关于C ++类空类大小1个字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文