English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C ++중간 클래스의 객체 크기는 얼마인가요?

공백 클래스 객체의 크기를 찾는 예제입니다.

예제

#include <bits/stdc++.h>
using namespace std;
class p1 {
   public:
   void first() {
      cout << "\n부모 클래스 p1 function is called.";
   }
};
class p2
{ };
int main() {
   cout << "객체의 크기는 non-empty class p1 =1);
   cout << "\nempty 클래스 객체의 크기는 " << sizeof(p2 =2);
   p2 p;
   cout << "\nempty 클래스 객체의 크기는 " << sizeof(p2 =
   p1 o;
   cout << "\n객체의 크기는 non-empty class p1 =
   return 0;
}

출력 결과

객체의 크기는 non-empty class p1 = 1
공백 클래스 객체의 크기는 p2 = 1
공백 클래스 객체의 크기는 p2 = 1
객체의 크기는 non-empty class p1 = 1

위 프로그램에서, 공백 클래스 p가 생성되었습니다2。

class p2
{ };

클래스와 객체의 크기 출력如下:

cout << "객체의 크기는 non-empty class p1 : " << sizeof(p1);
cout << "\nempty 클래스 객체의 크기는 " << sizeof(p2 : " << sizeof(p2);
p2 p;
cout << "\nempty 클래스 객체의 크기는 : " << sizeof(p);
p1 o;
cout << "\n객체의 크기는 non-empty class p1 : " << sizeof(o);
MongoDB 튜토리얼