C++ Problem, Finally!!

Started by
26 comments, last by ALH 19 years, 7 months ago
maybe you have to put using namespace std; after #include <iostream> in the header file
and in the other file just include the header file, without iostream
pex.
Advertisement
Don't put "using" in a header file at all, just use "std::istream" as is. You're unlikely to need it very often anyway.

Also, the most common place for a missing semi-colon is at the end of a class declaration:

class MyClass{}; //semi-colon here!
Kippesoep
Ok so in the header file I put:

using std::istream and everthing should be cool.

No, include iostream and no using namespace std; right?

Mark Coleman
VC also complains about semicolons when it misses a definition for a type:
class MyClass{};MyClassWithATypo variable; // <- syntax error missing ; before 'variable'
Quote:Original post by mrmrcoleman
and then using std::istream; in the h file??


not using.

#include <iostream>
//qualify it with std::
void someFunc(std::iostream& is);

putting

using namespace name;

brings all the names of functions, variables, classes etc into scope. So they could collide with some other functions, variables and classes of the same name.

putting

using name::whatever;

brings just 'whatever' from namespace 'name' into scope. So it is more restricted than putting using namespace name.

qualifying explictly

name::whatever

means nothing is brought into scope and you won't get name collisions.

You want to not have collisions, so don't put using in headers, use the explicit qualification.

There is one exception: if a derived class hides functions in the base class by overloading them, or if they are privately inherited, you can make them available by using using.
Quote:Original post by ALH
What about remove 'using namespace std;' and replace '#include <iostream>' with '#include <iostream.h>'?

Cheers,
ALH


No! Bad ALH! Go to your room.
This kind of thing has happened to me before when I was missing a semicolon somewhere else in my code, and the compiler happened to look at it just before it plunged into the iostream head file.

Make sure all your class and structure declarations have a semicolon following them. Check every line of code if your program is not tremendously large.
I'm gonna go with semi-colon. i always get the same 105 errors when i forget that.

class foo
{

}; <- IMPORTANT!
No bombs, No guns, just an army of game creators...
Ok thanks for all the feedback guys. I will go and see what I can do and hopefully all will be well.

Mark Coleman
Quote:Original post by glassJAw
No! Bad ALH! Go to your room.


Why that's bad? Be more explicit please...

ALH

This topic is closed to new replies.

Advertisement