64,281
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
class People{
public:
int id;
int age;
};
int main(int argc, char **argv) {
People p1;
People *p2=new People();
People p3;
string str1="Hello";
char *str2=new char(6);
printf("%d %d %d\n",&p1,p2,&p3);
printf("%d %d\n",sizeof(p1),sizeof(p2));
printf("%d %d\n",&str1,str2);
printf("%d %d\n",sizeof(str1),sizeof(str2));
return 0;
}
#include <string>
#include <cstdio>
class TheString : std::string
{
};
class People{
public:
int id;
int age;
};
int main(int argc, char **argv)
{
People p1;
People *p2=new People();
People p3;
std::string str1="Hello";
char *str2=new char(6);
printf("%p %p %p\n",&p1,&p2,&p3);
printf("%d %d\n",sizeof(p1),sizeof(p2));
printf("%p %p\n",&str1,&str2);
printf("%d %d\n",sizeof(str1),sizeof(str2));
return 0;
}
debug编译输出
ClCompile:
1> demo.cpp
1> class TheString size(32):
1> +---
1> | +--- (base class ?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@)
1> | | +--- (base class ?$_String_val@DV?$allocator@D@std@@)
1> | | | +--- (base class _Container_base12)
1> 0 | | | | _Myproxy
1> | | | +---
1> 4 | | | _Bxty _Bx
1> 20 | | | _Mysize
1> 24 | | | _Myres
1> 28 | | | ?$allocator@D _Alval
1> | | | <alignment member> (size=3)
1> | | +---
1> | +---
1> +---
1>
1>
1>
1>Manifest:
1> Deleting file "Debug\demo.exe.embed.manifest".
运行输出:
0027FDCC 0027FDC0 0027FDB0
8 4
0027FD88 0027FD7C
32 4
请按任意键继续. . .