【发布时间】:2012-01-04 05:26:39
【问题描述】:
如何通过引用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 +
<iostream>,并被告知你正在学习 C++。我会推荐a good introductory C++ book。
标签: c++ struct pass-by-reference