对象问题 [英] object question
问题描述
创建空类对象时分配了多少内存?
谢谢。
杰克
创建空类对象时分配了多少内存?
试试这个......
舱空
{
};
空e;
cout<<" \ nSizeof"<< typeid(e).name()<<" ="<< sizeof(空);
使用MSVC 8.0时输出为1
junw2 ... @ gmail.com写道:
创建空类对象时分配了多少内存? />
谢谢。
我想象这是获得一个类的b / b
类/实例大小的好方法 -
class DoNothing
{
public:
DoNothing(){}
// int a;
};
int main()
{
DoNothing donothing ;
std :: cout<< sizeof(donothing)<< std :: endl;
std :: cout<< sizeof(DoNothing)<< std :: endl;
}
* ju ****** @ gmail.com :
创建空类对象时分配了多少内存?
取决于编译器和上下文。
作为基类对象,它可以占用零字节,否则更多。
-
答:因为它弄乱了人们通常阅读文字的顺序。
问:为什么会这样这么糟糕吗?
A:热门帖子。
问:usenet和电子邮件中最烦人的是什么?
how much memory is allocated when creating an object of an empty class?
Thanks.
Jack
how much memory is allocated when creating an object of an empty class?
Try this...
class Empty
{
} ;
Empty e ;
cout<<"\nSizeof "<<typeid(e).name()<<" = "<<sizeof(Empty) ;
Output is 1 when using MSVC 8.0
junw2...@gmail.com wrote:how much memory is allocated when creating an object of an empty class?
Thanks.I imaging that this would be a good way of getting the size of a
class/instance of a class -
class DoNothing
{
public:
DoNothing() {}
//int a;
};
int main()
{
DoNothing donothing;
std::cout << sizeof( donothing ) << std::endl;
std::cout << sizeof( DoNothing ) << std::endl;
}
* ju******@gmail.com:how much memory is allocated when creating an object of an empty class?
Depends on the compiler and the context.
As a base class object it can occupy zero bytes, otherwise more.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
这篇关于对象问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!