1

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.

Edited by crystality: n/a

Comments
Went extra mile to post. :)
3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by crystality
Featured Replies
  • [QUOTE=crystality;1028094]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: [URL="http://users.cs.fiu.edu/~weiss/dsaa_c++/Code/mystring.h"]mystring.h[/URL] [URL="http://users.cs.fiu.edu/~weiss/dsaa_c++/Code/string.cpp"]string.cpp[/URL] [URL="http://users.cs.fiu.edu/~weiss/dsaa_c++/Code/SplayTree.h"]SplayTree.h[/URL] [URL="http://users.cs.fiu.edu/~weiss/dsaa_c++/Code/QueueAr.h"]QueueAr.h[/URL] And for fun: [URL="http://users.cs.fiu.edu/~weiss/dsaa_c++/Code/SplayTree.cpp"]SplayTree.cpp[/URL] [URL="http://users.cs.fiu.edu/~weiss/dsaa_c++/Code/QueueAr.cpp"]QueueAr.cpp[/URL] [CODE]#include <iostream> #include <fstream> … Read More

  • 1

    [QUOTE=noey699;1028141]i am not sure but it might be friend ostream& operator<< (ostream &, const GrabStuff&); needs a space between operator and << so it would be friend ostream& operator << (ostream &, const GrabStuff&);[/QUOTE] That is not an issue. I dont know why that error is coming though but I … Read More

1

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.

i am not sure but it might be
friend ostream& operator<< (ostream &, const GrabStuff&);
needs a space between operator and <<
so it would be
friend ostream& operator << (ostream &, const GrabStuff&);

1

i am not sure but it might be
friend ostream& operator<< (ostream &, const GrabStuff&);
needs a space between operator and <<
so it would be
friend ostream& operator << (ostream &, const GrabStuff&);

That is not an issue. I dont know why that error is coming though but I have tested it without space and works fine.


Error 2>

ostream& operator<< (ostream &os, const GrabStuff &name)
{
	os << name.myWord << " ";
	while (!myLineNumbers.isEmpty()) /*IN THIS LINE*******/
	{
		// blahblah		
	}
	return os;
}

Should have done

while (!name.myLineNumbers.isEmpty())
Comments
fixed my problem
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.