post #1 of 1
Thread Starter 
I can't figure out how to fix these errors I'm getting.

In this chapter, the class to implement the nodes of a linked list is defined as a
struct. The following rewrites the definition of the struct nodeType so
that it is declared as a class and the member variables are private.
Code:
template
class nodeType
{
public:
const nodeType& operator=(const nodeType&);
//Overload the assignment operator.
void setInfo(const Type& elem);
//Function to set the info of the node.
//Postcondition: info = elem;
Type getInfo() const;
//Function to return the info of the node.
//Postcondition: The value of info is returned.
void setLink(nodeType *ptr);
//Function to set the link of the node.
//Postcondition: link = ptr;
nodeType* getLink() const;
//Function to return the link of the node.
//Postcondition: The value of link is returned.
nodeType();
//Default constructor
//Postcondition: link = NULL;
nodeType(const Type& elem, nodeType *ptr);
//Constructor with parameters
//Sets info point to the object elem points to and
//link is set to point to the object ptr points to.
//Postcondition: info = elem; link = ptr
nodeType(const nodeType &otherNode);
//Copy constructor
~nodeType();
//Destructor
private:
Type info;
nodeType *link;
};

Write the definitions of the member functions of the class nodeType.
Also write a program to test your class.

Here's my code. I had to change nodeType to Node.
Code:
#pragma once
#include <iostream>
using namespace std;
template
class Node
{
private:
   Type info;
   Node *link;
public:
   // Constructors
   Node();
   Node(const Type& elem, Node *ptr);
   Node(const Node &otherNode);
   // Destructor
   ~Node();
   // Mutators and Accessors (getters and setters)
   void setInfo(const Type& elem);
   Type getInfo() const;
   void setLink(Node *ptr);
   Node * getLink() const;
   // Overload the assignment operator
   const Node & operator=(const Node&);
};
template Node::Node()
{
   link = NULL;
}
template Node::Node(const Type& elem, Node *ptr)
{
   info = elem;
   link = ptr;
}
template Node::Node(const Node &otherNode)
{
   otherNode.setInfo(info);
   otherNode.setLink(link);
}
template Node::~Node()
{
   // fill in this
}
template void Node::setInfo(const Type& elem)
{
   info = elem;
}
template Type Node::getInfo() const
{
   return info;
}
template void Node::setLink(Node *ptr)
{
   link = ptr;
}
template Node * Node::getLink() const
{
   return link;
}

template const Node & Node::operator=(const Node& n)
{
   info = n.info;
   link = n.link;
}

Main:
Code:
#include "Node.h"
#include <string>
#include <iostream>
using namespace std;
int main()
{
   Node *node1 = new Node();
   node1->setInfo("Hello");
   Node *node2 = new Node("Hello World!", node1);
   Node *node3 = new Node(*node2);
   Node *node4 = new Node();
   node4->setInfo("Foo Bar");
   node4->setLink(node3);
   cout << node3->getLink()->getInfo() << endl; // should return "hello world"
   system("pause");
   return 0;
}

These are the errors:
Error 1 error C2662: 'void Node::setInfo(const Type &)' : cannot convert 'this' pointer from 'const Node' to 'Node &'
Error 2 error C2662: 'void Node::setLink(Node *)' : cannot convert 'this' pointer from 'const Node' to 'Node &'