0
我嘗試了簡單的類和鏈表實現。 請幫我用這段代碼,因爲我正在收到 「list iterator not derefereenable」 運行代碼時。 感謝嘗試類與鏈接列表時出錯C++
#include<iostream>
#include<list>
#include<string>
using namespace std;
class Car
{
public:
void getType(string x)
{
type = x;
}
string showType()
{
return type;
}
private:
string type;
};
void main()
{
string p;
list<Car> c;
list<Car>::iterator curr = c.begin();
cout << "Please key in anything you want: ";
getline(cin, p);
curr->getType(p);
cout << "The phrase you have typed is: " << curr->showType() << endl;
}
有沒有在你的列表中,這樣'curr'沒有指向一個有效的'Car',您需要將車添加到您的列表 – vu1p3n0x
名爲'的getType()'setter是? –