gpt4 book ai didi

C++ 通过引用传递 : two level deep function calls

转载 作者:太空宇宙 更新时间:2023-11-04 14:26:25 24 4
gpt4 key购买 nike

我在 C++ 中有类似的代码。当我尝试运行它时它中止了。这种类型的代码行得通吗?

在主函数中:

type* a = something
type* b = something
func1(a,b);

func1 声明:

void func1(type* &a, type* &b){
func2(a,b);
// do something
}

func2如下

void func2(type* &a, type* &b){
// do something
}

这些函数调用是否会按应有的方式工作。我应该修改 a 和 b,因为它们是通过引用传递的。

谢谢

最佳答案

是的,如果你在 'func1 或 'func2 中修改 'a 或 'b 就应该这样做。

关于C++ 通过引用传递 : two level deep function calls,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3640307/

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