【发布时间】:2014-02-11 05:49:59
【问题描述】:
这是这个问题的延续,一些好心人已经帮助了我:Passing a string pointer to a struct in C++
我试图通过pointer 将各种strings 传递给Struct 的成员,但我做的事情根本不正确。我认为它不需要被取消引用。以下过程适用于其他类型的数据,例如 int 或 char。例如:
typedef struct Course{
string location;
string course;
string title;
string prof;
string focus;
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* or argument ‘2’ to ‘void c_Init
【问题讨论】:
标签: c++ string pointers struct