For class, I am trying to overload the << operator so I can print out an object I created. I declared and added to this
WORD you; //this is a linked list that contains 'y' 'o' 'u'
and I want to do this
cout << you; //error: no operator "<<" matches theses operands
I have to overload the insertion operator as a friend function with chaining to print a word.
I have declared and defined the overloaded function, but it still does not work. Here is the class declaration file, followed by the .cpp file with the function
#include <iostream>
using namespace std;
#pragma once
class alpha_numeric //node
{
public:
char symbol; //data in node
alpha_numeric *next;//points to next node
};
class WORD
{
public:
WORD(); //front of list initially set to Null
//WORD(const WORD& other);
bool IsEmpty(); //done
int Length();
void Add(char); //done
void Print(); //dont
//void Insert(WORD bword, int position);
//WORD operator=(const string& other);
friend ostream & operator<<(ostream & out, alpha_numeric *front);//******************<-----------------
private:
alpha_numeric *front; //points to the front node of a list
int length;
};
In the .cpp file, I put *front in the parameter because it said front was not defined when I tried to use it inside the function, even though I declared it in the class. I then tried this. I have no clue if it is correct.
ostream & operator<<(ostream & out, alpha_numeric *front)
{
alpha_numeric *p;
for(p = front; p != 0; p = p -> next)
{
out << p -> symbol << endl;
}
}
ostream& operator<<(ostream &out, WORD &word)?