如何通過引用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)。 –