C++编译器如何完成面向对象理论向计算机程序的转化
#include<stdio.h>
//////c++对象模型和结构体一样
class Test
{
int i;
int j;
short k;
short l;
static int c;
public:
Test(int i,int j,int k)
{
this->i=i; //this指针
this->j=j;
this->k=k; ///this的作用
}
void print()
{
printf("Object Address:%08x\n",this);
printf("&c=%08x,c=%d\n",&c,c);
printf("&i=%08x,i=%d\n",&i,i);
printf("&j=%08x,j=%d\n",&j,j);
printf("&k=%08x,k=%d\n",&k,k);
}
};
int Test::c; ///这一句非常重要
int main()
{
Test t1(1,2,3);
printf("&t1=%08x\n",&t1);
t1.print();
Test t2(4,5,6);
printf("&t2=%08x\n",&t2);
t2.print();
printf("sdfasdf.......");
getchar();
return 0;
}
静态成员函数没有this指针
普通成员函数有this指针