How to retrieve values of attributes in C++

264 views Asked by At

I'm trying to compare the string in my linked list to a string in a new node so i can compare them alphabetically. My compiler expected a primary expression before '->'. How can i use the values in my linked list as variables and compare strings?

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

There are 1 answers

5
pm100 On BEST ANSWER

maybe you mean

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

element is the name of a type not a variable. This code has an infinite loop in it, but I assume you will fix that once you get it to compile

Also, please post the exact error message and comment the line it points to in any question you post with compiler errors.