我不能讓這個程序正確編譯。這是一個單獨鏈接的程序。這個特殊的功能給我垃圾沒有轉換的東西在字符串中,但我看不到它。我得到了一個人的幫助,他告訴我要解決另一個問題,這個函數必須接受字符串而不是char *。我想我修復了所有與用字符串替換char *有關的錯誤,但我似乎無法修復這最後一個錯誤。請請幫助我! 這裏的問題是功能:爲什麼我會收到錯誤:無法將'std :: string {aka std :: basic_string <char>}'轉換爲'char *'賦值?
List_Node *listTextEditor::create_node(string value)//creates the list elements
{
struct List_Node *tempNode, *s;
tempNode = new(struct List_Node);
if (tempNode == NULL)
{
cout << "Memory not allocated " << endl;//if theres nothing in the list
return 0;
}
else
{
tempNode->textLine=value ; //This puts stuff in the current node and creates/moves to the next. THIS IS WHERE THE PROBLEM IS!!!!!!!!!
tempNode->nextEle = NULL;
return tempNode;
}
}
是textLine一個字符串類的成員數據? – Raindrop7
沒有從'std :: string'到(可變)'char *'的隱式轉換。另外,與你的問題無關:'if(tempNode == NULL)'永遠不能評估爲'true'。看看[新操作員](http://en.cppreference.com/w/cpp/memory/new/operator_new)是做什麼的。 – IInspectable
添加你的類的示例接口 – Raindrop7