error: expected constructor, destructor, or type

Good day,

This is the first time as a newcomer I have absolutely no idea what an error means. It says the following: "error: expected constructor, destructor, or type conversion before '&' token"
And it's happening for the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

using std::string;
using std::cout;
using std::cin;
using std::endl;

istream& taker(istream&); //line at which the error occurs.

int main() {

	//let the compiler place the return statement
}


The error is triggered because of an error in the prototype for the function named taker.
Can somebody please tell me what I'm doing wrong ?

Sincerely,

Jose.
Oops.
std::istream& taker(std::istream&); //Note the std::, as istream is a member of the namespace std.

-Albatross
Last edited on
Thank you Albatross.

What If I want to use a using statement to simplify that? Can I do it? how?

Good job. !
isn't it is better to use "using namespace std;" then you don't have to worry about putting the class scope for cin and cout etc.


Rave,

If I do that can I also get rid of the following: ?

1
2
3
4
using std::string;
using std::cout;
using std::cin;
using std::endl;


Thank you.
Yes you can, although it's often seen a a bad habit. Not sure anymore why, but Disch, i think, once explained me why :D
I think it has to do with some names you might choose for variables, that are actually in the std namespace. Like counter I think.

~Xander
Alright, Would be nice if Disch could respond to this, but asides from that, I believe I have learned my lesson. Thank you guys.

Thank you very much !
I'm not Disch but I'll do my best :)

When you bring the entire std namespace into the global namespace (by using namespace std;) you bring a lot of names you won't use and which might cause name clashes. A common example is std::count(), but depending on the kind of application you're writing many more could arise.
Thank you very much filipe !, your explanation is worthy to me. I've read that C++ has a lot of problems with name collisions. so that's nice to know.

Keep up the good work.
Topic archived. No new replies allowed.