c++ - 如何在 C++ 中检索属性值
问题描述
我正在尝试将链接列表中的字符串与新节点中的字符串进行比较,以便按字母顺序进行比较。我的编译器在“->”之前需要一个主表达式。如何将链接列表中的值用作变量并比较字符串?
struct element {
std::string woord;
struct element * next = NULL;
};
void VoegToeAlfabetisch(element** lijst, std::string tekst)
{
element* x(new element);
x->woord = tekst;
while (*lijst != NULL) {
std::string print = element->woord;
}
}
int main()
{
element* root = NULL;
VoegToeAlfabetisch(&root, "Alfabetisch");
return 0;
}
解决方案
也许你的意思是
std::string print = (*lisjt)-> word
element 是类型而不是变量的名称。这段代码中有一个无限循环,但我假设你会在编译后修复它
此外,请发布确切的错误消息,并在您发布的任何带有编译器错误的问题中评论它所指向的行。