面向对象,全局函数和成员函数之间的转换
Posted jefy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了面向对象,全局函数和成员函数之间的转换相关的知识,希望对你有一定的参考价值。
class A
{
private:
int a;
int b;
public:
A(int a, int b)
{
this->a = a;
this->b = b;
}
{
private:
int a;
int b;
public:
A(int a, int b)
{
this->a = a;
this->b = b;
}
A Test(A &aa)
{
A temp = A(this->a + aa.a, this->b + aa.b);
cout << temp.a << "b:" << temp.b << endl;
return temp;
}
{
A temp = A(this->a + aa.a, this->b + aa.b);
cout << temp.a << "b:" << temp.b << endl;
return temp;
}
A &Test1(A &Aa)
{
this->a = this->a + Aa.a;
this->b = this->b + Aa.b;
return *this;
}
{
this->a = this->a + Aa.a;
this->b = this->b + Aa.b;
return *this;
}
void print()
{
cout << this->a << "b:" << this->b << endl;
}
};
{
cout << this->a << "b:" << this->b << endl;
}
};
void main()
{
A a1(1, 2);
A a2(3, 4);
a1.Test1(a2);
//a2.Test(a1);
a1.print();
system("pause");
}
{
A a1(1, 2);
A a2(3, 4);
a1.Test1(a2);
//a2.Test(a1);
a1.print();
system("pause");
}
以上是关于面向对象,全局函数和成员函数之间的转换的主要内容,如果未能解决你的问题,请参考以下文章
面向对象:类的成员---只是特定(类的)命名空间的全局变量(函数)而已