Я пытаюсь передать различные string
s в члены Struct
через pointer
, но я делаю что-то принципиально неправильное. Я думаю, что это не нужно разыгрывать. Процесс ниже работает для других типов данных, таких как int
или char
. Например:Передача строки указателю на структуру в C++
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*, ..