I am working on a homework assignment where we aren’t allowed to use any STL containers. My implementation of LinkedList is a collection of Nodes that are chained together with pointers. I have another class called ContinuousList which has a data member LinkedList whose Nodes contain pointers to Nodes in various other LinkedLists. I’m trying to assign the return value of a function that returns a pointer to a Node to a variable that is also a pointer to a Node, but it is saying that is invalid and I don’t understand why I can’t do that.
template <typename ValueType>
struct Node
{
Node();
std::string m_key;
ValueType m_value;
Node<ValueType>* m_next;
};
The linked list class:
template <typename ValueType>
class LinkedList
{
public:
Node<ValueType>* begin()
{
return m_head;
}
private:
Node<ValueType>* m_head;
};
ContinuousList:
template <typename ValueType>
class ContinuousList
{
public:
ValueType* iterate(std::string& key)
{
m_curr = m_collection.begin(); // Error occurs here
...
}
private:
LinkedList<Node<ValueType>*> m_collection;
Node<ValueType>* m_curr;
};
Full error message
1> error C2440: '=' : cannot convert from 'Node<ValueType> *' to 'Node<ValueType> *'
1> with
1> [
1> ValueType=Node<bool> *
1> ]
1> and
1> [
1> ValueType=bool
1> ]
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1> while compiling class template member function 'bool *ContinuousList<ValueType>::iterate(std::string &)'
1> with
1> [
1> ValueType=bool
1> ]
1> see reference to class template instantiation 'ContinuousList<ValueType>' being compiled
1> with
1> [
1> ValueType=bool
1> ]
this
is making m_head be
Which is not what you want.
if
was what you wanted, use
m_collection.begin()->m_value;
or use
and it will return Node
Though I may just be really tired…. =D