node &getNode(int index) {                                                 //NOT TESTED
        if (index <= getLength() || index >= 1){
            temp = new node;
            temp = head;
            for (int i=index-1; i>0; i--){
                temp = temp->next;
            }
            return &temp;
        }   
    }

Hi everyone,
I receive this error msg:

invalid initialization of non-const reference of type 'node&' from a temporary of type 'node**'

I cannot change the return type of the method so how can i return that reference.
Thanks

wow i've done it. It should be "return **&temp;"

node &getNode(int index) { //NOT TESTED
if (index <= getLength() || index >= 1){
temp = new node;
temp = head;
for (int i=index-1; i>0; i--){
temp = temp->next;
}
return &temp;
}
}

Hi everyone,
I receive this error msg: "invalid initialization of non-const reference of type 'node&' from a temporary of type 'node**' "

I cannot change the return type of the method so how can i return that reference.
Thanks

I really dont know whats going on here, there are a few things that are weird.

One, you method should be returning Node* not Node&. Also, when you declare a new object of type Node, it should be

Node* temp = new Node;

If you do those things then you don't have to return anything special, just return temp.

I hope that function is not public!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.