gpt4 book ai didi

c++ - 在函数中更改类实例的值

转载 作者:行者123 更新时间:2023-11-28 01:47:17 25 4
gpt4 key购买 nike

<分区>

我编写了以下代码来测试如何在函数中更改类对象的值。

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。是因为我无法更改类实例的值,就像我无法在不使用指针的情况下更改数组成员的值一样吗?如果有人能澄清这一点,我将不胜感激!

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com