【发布时间】:2014-03-08 18:06:02
【问题描述】:
我试图通过pointer 将各种strings 传递给Struct 的成员,但我做的事情根本不正确。我认为它不需要被取消引用。以下过程适用于其他类型的数据,例如 int 或 char。例如:
typedef struct Course {
string location[15];
string course[20];
string title[40];
string prof[40];
string focus[10];
int credit;
int CRN;
int section;
} Course;
void c_SetLocation(Course *d, string location){
d->location = location;
. . .
}
当我尝试编译以下算法来初始化 Course 时出现错误:
void c_Init(Course *d, string &location, ... ){
c_SetLocation(d, location[]);
. . .
}
错误:
error: cannot convert ‘const char*’ to ‘std::string* {aka std::basic_string<char>*}’ for argument ‘2’ to ‘void c_Init(Course*, std::string*, ..
【问题讨论】:
标签: c++ string pointers struct