C++??????????г???????????
???????????? ???????[ 2013/4/10 9:47:47 ] ????????
??????????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;
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11