- #include<iostream>
- using namespace std;
- class test
- {
- private:
- int t;
- public:
- test():t(0)
- {}
- test(int tes):t(tes)
- {}
- void add(test t1,test t2)
- {
- t=t1.t+t2.t; /* 同类对象在其内部函数中可直接调用同类对象的私有变量运算 */
- }
- void show()
- {
- cout<<t;
- }
- };
- int main()
- {
- test t1;
- test t2(2);
- test t3;
- t3.add(t1,t2);
- t3.show();
- return 0;
- }
同类对象私有变量
最新推荐文章于 2021-02-28 13:59:47 发布