【发布时间】:2017-11-15 18:35:12
【问题描述】:
我编写了以下代码来测试如何在函数中更改类对象的值。
using namespace std;
class test{
public:
int a;
};
void runer(test testXX){
testXX.a=10;
}
int main()
{
test test1;
test1.a=5;
runer(test1);
cout<<test1.a;
return 0;
}
当我运行以下代码时,输出是 5 而不是 10。是因为我无法更改类实例的值,就像我无法在不使用指针的情况下更改数组成员的值一样?如果有人能澄清这一点,我将不胜感激!
【问题讨论】:
-
你的意思可能是
void runer(test& testXX)