如何通过引用C++传递结构参数,请参阅下面的代码。通过引用传递结构参数C++
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;
struct TEST
{
char arr[20];
int var;
};
void foo(char * arr){
arr = "baby"; /* here need to set the test.char = "baby" */
}
int main() {
TEST test;
/* here need to pass specific struct parameters, not the entire struct */
foo(test.arr);
cout << test.arr <<endl;
}
希望的输出应该是宝贝。
看起来您正在学习C +'',并被告知您正在学习C++。我会推荐[一本很好的C++入门书](http://stackoverflow.com/q/388242/46642)。 –