Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question about std namespace

Status
Not open for further replies.

himbo

Programmer
Feb 3, 2003
2
0
0
CA
Hey,
I'm using Visual C++ 6. I'm having a problem overloading operators as friends. Everything works fine when I don't bring the std namespace into scope, but when I do I get error messages saying that the function cannot access the private data of the class. Basically I want to know what the issue is with this, and if there is a workaround that is not making all the data public, or using a accessor method.

thanks

 
instead of specifying [tt]using namespace std;[/tt]

try putting [tt]std::[/tt] in front of all std stuff - this will keep it separate from everything else. eg:

instead of

[tt]using namespace std;

cout << &quot;Hello&quot; << endl;[/tt]

just do this:

[tt]

std::cout << &quot;hello&quot; << std::endl;[/tt]

tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
also

std::eek:stream& operator<< (std::eek:stream& out, myclass xxx)
{
...
return out;
}

By the way, STL files with extension .h are deprecated. If you hafe something like <iostream.h> <fstream.h> .... use <iostream> <fstream> ... instead of all of them. Ion Filipski
1c.bmp


filipski@excite.com
 
I agree with IonFilipski. You should also avoid to use old and new stdlib header files in one project. And do not use 'using namespace' in header files.
 
thanks everyone for you help it is appreciated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top