所以我得到了这个:
错误:类型参数与类型
"Person *"
不兼容"Person *"
我不知道我做错了什么。我确定这是愚蠢的,但如果有人能指出它会很棒。
LL* g_list;
int size = 50;
char getOption();
int main()
{
char input;
bool running = true;
g_list = new LL;
char* name = new char[size];
char* color = new char[size];
cout << "enter name: ";
cin >> name;
cout << "enter color: ";
cin >> color;
Person* pers = new Person(name, color);
g_list->addBack(pers); //error
return 0;
}
//LL.cpp file (linked list)
void LL::addBack(Person* pobj)
{
if (count_ == 0)
{
head_ = pobj;
}
else
{
Person* ptr = head_;
for (int i = 0; i < count_ - 1; i++)
{
ptr = ptr->next_;
}
ptr->next_ = pobj;
}
count_++;
pobj->next_ = 0;
return;
}
//Person constructor
Person::Person(char* name, char* color)
{
name_ = new char[strlen(name)];
strcpy(name_, name);
color_ = new char[strlen(color)];
strcpy(color_, color);
next_ = 0;
}
让我知道是否需要更多信息。