??????????C++??????б??????????????????????κε????????????????????????????get??set???????????????????????????????????????????????????get??set????????????????ж???????????????????????????.o???????????????п?????????????????????????????????????????????????в?????????????????????????????????????????????????????????г???κ?????Σ?????????????????????????????????????????????????????????????????ε????????????????????????????

????????1?????????

?????????????

#include<iostream.h>

class A
{
 int t;
public:
 A()
 {
  t=2002;//????????г???????????t

 }
 friend class B;//?????????classB

};

class B
{
public:
 A a;
 int sum()
 {
  return a.t+1500;//???class B????class A?е???г??????t

 }
};

void main()
{
 B b;
 cout<<b.sum()<<endl;
}

????????2??????????

???????????????

?????????????C++????????????????η???????е????????????????????δ???????Σ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????3????д????θ???????b?????

#include <iostream>
#include <string>
using namespace std;

class center
{
public:
 void setX(float _x){x=_x;}
 void setY(float _y){y=_y;}
 void setMeanValue(float avg){meanValue=avg;}
 float getX(){return x;}
 float getY(){return y;}
 float getMeanValue(){return meanValue;}
 center():x(0.0)??y(0.0)??meanValue(0.0){}
private:
 float x;
 float y;
 float meanValue;
};

int main()
{
 center A;
 //??????????????;
 A.setX(1.0);
 A.setY(4.0);
 A.setMeanValue(13.0);
 cout<<A.getX()<<" "<<A.getY()<<" "<<A.getMeanValue()<<endl;
 
 //???????????????;
 //*((float*)&A):??center????A????????????????????int*?????????????????
 float tmp = *((float*)&A);
 cout<<tmp<<endl;//???A.x???
 tmp = *((float*)&A + 1);
 cout<<tmp<<endl;//???A.y???
 *((float*)&A + 2)=2;//???A.meanValue???
 cout<<A.getMeanValue()<<endl;
}