1 Star 0 Fork 0

刘小虎 / my-study-notes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
t3.cpp 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
刘小虎 提交于 2019-12-19 22:17 . add files.
#include <iostream>
#include <stdio.h>
using namespace std;
class A {
public:
int pub_i1;
int pub_i2;
void pub_foo1() {
cout << "A::prv_i1 addr: " << &prv_i1 << endl;
cout << "A::prv_i2 addr: " << &prv_i2 << endl;
printf("A::prv_foo1() addr: %p\n", (void *)&A::prv_foo1);
printf("A::prv_foo2() addr: %p\n", (void *)&A::prv_foo2);
}
void pub_foo2() {}
virtual void pub_vfoo1() {}
virtual void pub_vfoo2() {}
private:
int prv_i1;
int prv_i2;
void prv_foo1() {}
void prv_foo2() {}
};
class B : public A {
};
int main()
{
A a;
cout << "sizeof A: " << sizeof(A) << endl;
cout << "a addr: " << &a << endl;
cout << "A::pub_i1 addr: " << &a.pub_i1 << endl;
cout << "A::pub_i2 addr: " << &a.pub_i2 << endl;
printf("A::pub_foo1() addr: %p\n", (void *)&A::pub_foo1);
printf("A::pub_foo2() addr: %p\n", (void *)&A::pub_foo2);
printf("A::pub_vfoo1() addr: %p\n", (void *)&A::pub_vfoo1);
printf("A::pub_vfoo2() addr: %p\n", (void *)&A::pub_vfoo2);
a.pub_foo1();
void **__vptr = (void **)&a;
void **virtual_table = (void **)(*__vptr);
printf("virtual table[0]: %p\n", virtual_table[0]);
printf("virtual table[1]: %p\n", virtual_table[1]);
//IT刘小虎
return 0;
}
1
https://gitee.com/popkx/my-study-notes.git
git@gitee.com:popkx/my-study-notes.git
popkx
my-study-notes
my-study-notes
master

搜索帮助