如何在C ++中检索属性值

时间:2018-06-26 15:09:52

标签: c++ linked-list

我正在尝试将链接列表中的字符串与新节点中的字符串进行比较,以便可以按字母顺序对它们进行比较。我的编译器期望在'->'之前有一个主表达式。如何将链表中的值用作变量并比较字符串?

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;
}

1 个答案:

答案 0 :(得分:4)

也许你是说

std::string print = (*lisjt)-> word

element是类型的名称,而不是变量。这段代码中有一个无限循环,但是我想一旦您将其编译就可以解决

此外,请在发布任何有关编译器错误的问题中发布确切的错误消息并注释其指向的行。

相关问题