ostream & operator << (ostream & o, const mouse m)
{
// PRINT MOUSE
o << "M";
return o;
}
Then I get the error: binary '<<' : no operator defined which takes a right-hand operand of type 'class mouse' (or there is no acceptable conversion)
I'm not sure if you put friend in from of the word ostream but when I tried I got 3 errors, including the first: '<<' : a friend function can only be declared in a class
'<<' : 'void' function returning a value
Anyone know whats going wrong? If you want I'll post the code, don't think its really nessicary seeing as I'm probably just missing something.
I'll post the code for the mouse.h and mouse.cpp, also I have uploaded a zip with mouse.h, mouse.cpp, and main.cpp. assume maze works (cause it does).
PHP Code:
#include <iostream>
using std:: ostream;
using std::endl;
#include "maze.h"
//#include "screen.h"
class mouse
{
protected:
unsigned short x;
unsigned short y;
unsigned int steps;
// N = 1; E = 2; S = 3; W = 4;
unsigned int direction;
char footprint;
bool righthand;
I sliced out everything that had to do with the maze class, and simply compiled your mouse.cpp and .h with a skeleton main function, and there were no errors (gcc under Linux).
Actually, I just figured out what your problem is =). Its this line:
Code:
cout << "M";
cout isnt defined, because you dont import it from the std namespace. Either #include <iostream.h> instead of #include <iostream> or add:
Code:
using std::cout;
to the top of the mouse.h file.
It compiled for me because I always use iostream.h, which imports the std namespace.
I fixed it! Well rather than fixing it I compromised. I turned mouse into a template class and al seems well. Go figure! I tried what you said Z and it worked (compiled) but when I added the maze stuff back it reverted back t how it was. I guess something from maze, maybe its friend ostream, did something.
Anyway, I'm happy it works now!!! Thanks Z and everyone else who have helped me!