需要补充。。

1. 注意虚函数的指针占4个字节。(当然是32位机器)

#include <cstdlib>
#include <ctime>
#include <iostream> #include <string.h> using namespace std; class A {
public:
const int a;
}; class B {
}; class C {
public:
~C()
{}
}; class D : public C {
public:
~D()
{}
}; class E {
public:
void print() {};
}; class F : public E {
public:
void print() {};
}; class G {
public:
virtual void print() {};
}; class H : public G {
public:
void print() {};
}; int main()
{
cout << "sizeof(A) = " << sizeof(A) << endl; //
cout << "sizeof(B) = " << sizeof(B) << endl; //
cout << "sizeof(C) = " << sizeof(C) << endl; //
cout << "sizeof(D) = " << sizeof(D) << endl; //
cout << "sizeof(E) = " << sizeof(E) << endl; //
cout << "sizeof(F) = " << sizeof(F) << endl; //
cout << "sizeof(G) = " << sizeof(G) << endl; //
cout << "sizeof(H) = " << sizeof(H) << endl; // return ;
}

C++ 对象的sizeof问题的更多相关文章

  1. C语言中的sizeof()

    sizeof,一个其貌不扬的家伙,引无数菜鸟竟折腰,小虾我当初也没少犯迷糊,秉着"辛苦我一个,幸福千万人"的伟大思想,我决定将其尽可能详细的总结一下. 但当我总结的时候才发现,这个 ...

  2. 数组类型与sizeof与指针的引用

    以char类型为例: char a[100];     //a类型为char[100]    &a类型为 char (*)[100]    *a类型为char char *p = a;     ...

  3. 全面解析sizeof(上) 分类: C/C++ StudyNotes 2015-06-15 10:18 188人阅读 评论(0) 收藏

    以下代码使用平台是Windows7 64bits+VS2012. sizeof是C/C++中的一个操作符(operator),其作用就是返回一个对象或者类型所占的内存字节数,使用频繁,有必须对齐有个全 ...

  4. 全面总结sizeof的用法(定义、语法、指针变量、数组、结构体、类、联合体、位域位段)

    一.前言 编译环境是vs2010(32位). <span style="font-size:18px;">#include<iostream> #inclu ...

  5. sizeof 跟 strlen 的区别

    1.参数 sizeof是c/c++ 中的一个操作符,其作用是返回对象或数据类型所占的内存字节数. 用法:sizeof(对象).sizeof 对象.sizeof(类型) 如果类型做参数,返回的是该类型所 ...

  6. sizeof进行结构体大小的判断

    typedef struct{    int a;    char b;}A_t;typedef struct{    int a;    char b;    char c;}B_t;typedef ...

  7. C语言sizeof陷阱

    执行以下程序,查看输出: #include <stdio.h> #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0])) int  ...

  8. sizeof运算符

    sizeof运算符返回一条表达式或一个类型名字所占的字节数.sizeof运算符满足右结合律,其所得的值是一个size_t类型的常量表达式.运算符的运算对象有两种形式: sizeof(type) siz ...

  9. sizeof()用法

    参考:sizeof_百度百科 sizeof()用法汇总(经典) 声明:本文是笔者抽出对自己有用的细节,对前两文的总结. 1.sizeof概念 sizeof是C语言中判断数据类型或者表达式长度符:不是一 ...

随机推荐

  1. 【BZOJ】1045: [HAOI2008]糖果传递(中位数)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1045 白书上有讲 没ac的坑点在,数据范围n<=1,000,000 #include < ...

  2. thinkPHP中phpexcel的导出功能

    public function wExcel() { vendor("PHPExcel.PHPExcel"); // Create new PHPExcel object $obj ...

  3. &lt;LeetCode OJ&gt; 217./219. Contains Duplicate (I / II)

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  4. Loadrunner_http长连接设置

    最近协助同事解决了几个问题,也对loadrunner的一些设置加深了理解,关键是更加知其所以然. ljonathan http://www.51testing.com/html/48/202848-2 ...

  5. print多重打印

    遇见有趣的问题必须记录下来,当时的想法思路也要记下来 以下两行代码打印出来的结果会是什么 print('2 * 3 = %d' % (2 * 3)) print('2 * 3 = %d' % 2 * ...

  6. 转载 -- Cocoapod方式引入百川SDK -报错[!] Unable to find a specification for `xxx`

    [cocopad集成百川sdk官网] iOS需要填写BundleID .BundleID要是当前应用的BundleID.勾选淘宝登录基础包下载SDK. 注意事项:将下载的SDK中的身份图片yw_122 ...

  7. org.apache.hadoop.yarn.exceptions.InvalidAuxServiceException: The auxService: mapreduce_shuffle do

    在yarn-site.xml 配置文件中增加: <property> <name>yarn.nodemanager.aux-services</name> < ...

  8. JS图片加载时获取图片宽高信息

    ; var img = new Image(); img.src = node.find("img[class='img1_1']").attr("src"); ...

  9. AI画圆角矩形

    如何画圆角矩形:设置矩形圆角大小 第一种方法:点击圆角矩形在画布上点一下; [caption id="attachment_878" align="alignnone&q ...

  10. JRebel插件安装配置与破解激活(多方案)详细教程

    JRebel 介绍 IDEA上原生是不支持热部署的,一般更新了 Java 文件后要手动重启 Tomcat 服务器,才能生效,浪费不少生命啊.目前对于idea热部署最好的解决方案就是安装JRebel插件 ...