Search code examples
c++templatestypesreturnmismatch

C++: Returning a templated object from a class, template type mismatch?


I have the following source code with a compiler error. Its obvious what I'm trying to do so I won't try explaining besides by saying that the type node<N>* being returned is not the correct type because it is a template and thats creating a conflict with the session* object. Heres the error.

linked_list_1.cpp|17|error: cannot convert 'node<session*>*' to 'session*' in assignment|

Solution

  • In line 17, you want to assign the return value of return_node to a session*, but the return type of return_node is a Node<N>* (Node<Session*>*) and not a N (session*). Add an accessor function to the node class, and use it to access the data member, e.g:

    session* SESSION_COPY;
    SESSION_COPY =  LIST->return_node(0)->getData();