c++ pass by reference : two level deep function calls
I have code similar to this in c++. It aborts when i try to run it. Would this type of code work ?
In the main function :
type* a = something
type* b = something
func1(a,b);
func1 declaration:
void func1(type* &a, type* &b){
func2(a,b);
// do something
}
开发者_StackOverflow中文版func2 is as follows
void func2(type* &a, type* &b){
// do something
}
Will these function calls work the way it should. I should have a and b modified because they are passed by reference.
Thanks
Yes, it should if you modify 'a or 'b in 'func1 or 'func2.
Yes, the global variables a and b can be changed by either of these functions, in addition to the contents of whatever they're pointing at.
精彩评论