Hi! I'm getting this error when compiling:
$ g++ index.cpp
index.cpp:85: error: 'friend' used outside of class
index.cpp: In function 'std::ostream& operator<<(std::ostream&, const GrabStuff&)':
index.cpp:88: error: 'myLineNumbers' was not declared in this scope
Links to included files:
mystring.h
string.cpp
SplayTree.h
QueueAr.h
And for fun:
SplayTree.cpp
QueueAr.cpp
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
#include "mystring.h"
#include "string.cpp"
#include "SplayTree.h"
#include "QueueAr.h"
class GrabStuff
{
public:
GrabStuff();
GrabStuff(string);
~GrabStuff();
void setWord (string);
string getWord ();
void setLineNumber (int);
[B]friend ostream& operator<< (ostream &, const GrabStuff&);[/B]
private:
string myWord;
Queue<int> myLineNumbers;
Queue<int> temp;
};
GrabStuff::GrabStuff()
{}
GrabStuff::GrabStuff(string s) { myWord = s; }
GrabStuff::~GrabStuff() {}
void GrabStuff::setWord (string w) { myWord = w; }
string GrabStuff::getWord () { return myWord; }
void GrabStuff::setLineNumber (int num) { myLineNumbers.enqueue(num); }
ostream& operator<< (ostream &os, const GrabStuff &name)
{
os << name.myWord << " ";
[B]while (!myLineNumbers.isEmpty())[/B]
{
// blahblah
}
return os;
}
What am I doing wrong? ='( I've literally looked at this for three hours. HELP! =) Thanks.