相关疑难解决方法(0)

为什么班级的大小为零?如何确保不同的对象具有不同的地址?

我创建了一个类,但它的大小为零.现在,我怎样才能确定所有对象都有不同的地址?(我们知道,空类的大小不为零.)

#include<cstdio>
#include<iostream>
using namespace std;
class Test
{
    int arr[0];//Why is the sizezero?
};

int main()
{
    Test a,b;  
      cout <<"size of class"<<sizeof(a)<<endl;
       if (&a == &b)// now how we ensure about address of objects ?
          cout << "impossible " << endl;
       else
          cout << "Fine " << endl;//Why isn't the address the same? 

        return 0;
}        
Run Code Online (Sandbox Code Playgroud)

c++ class

4
推荐指数
2
解决办法
366
查看次数

标签 统计

c++ ×1

class ×1