<分区>
Possible Duplicate:
C++: What is the size of an object of an empty class?
#include <iostream>
class C
{
};
int main()
{
std::cout << sizeof(C) << std::endl;
return 0;
}
输出: 1
为什么是 1,而不是零?
标签 c++
<分区>
Possible Duplicate:
C++: What is the size of an object of an empty class?
#include <iostream>
class C
{
};
int main()
{
std::cout << sizeof(C) << std::endl;
return 0;
}
输出: 1
为什么是 1,而不是零?
最佳答案
出自 Stroustrup 之口 sizeof. To ensure that the addresses of two different objects will be different. For the same reason, "new" always returns pointers to distinct objects.
关于c++ - sizeof(空白类)== 1. 为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3132588/
相关文章:
c++ - 使用指向非静态成员函数的函数指针时,可以省略 "this"关键字吗
c++ - Qt : Background thread refreshing UI thread
c++ - 异常抛出 : Access violation reading location in VS 2012.(在 VS2010 中没有)
c++ - Qt 4.8.0 - 未列出 MySQL 驱动程序
使用 Visual Studio 2010/Intel 2013 创建的 C++/Fortran 项目不会在 Visual Studio 2015/Intel 2017 中以 Release模式构建
c++ - 无法让 GetModuleFileNameA 工作,不断收到错误 'missing type specifier...'