Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 31st, 2005, 6:35 PM   #21
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Quote:
Cerulean, you actually scanned all the 245,000 google results for using namespace std and determined that
No uhh I got a bot to do it for me. I'm talking from what i've experienced to have been said by programmers that I hold in high esteem.

Quote:
but just to save you the trouble of typing std:: before every cout and cin call, try "using std::cin" and "using std::cout".
Sure, i'm fine with that. You're not polluting the global namespace, and you're perfectly aware of what names you're using. To be honest I prefer just typing the 'std::'. I don't like interrupting workflow by going back to the top and adding a using directive - personal preference, personal preference.
Cerulean is offline   Reply With Quote
Old Jul 31st, 2005, 9:25 PM   #22
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Oh well, we can never agree. I get the feeling that you're still angry over that discussion about opensource software that we had a few weeks ago.
OpenLoop is offline   Reply With Quote
Old Aug 1st, 2005, 12:51 PM   #23
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
In total honesty I did not remember it was you that I had that discussion with, nor was I angry because I had opposing views to someone else in a discussion. Anger is too silly a thing to waste time on anyhow
Cerulean is offline   Reply With Quote
Old Aug 1st, 2005, 1:12 PM   #24
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
very well said :-)

By the way you have to admit "gimp" is a horrible name for a piece of software.
__________________
Few people deserve to be compared to (Rush) Limbaugh, most of them were convicted at the Nuremburg trials.
--WilliamSChips on Slashdot
uman is offline   Reply With Quote
Old Aug 1st, 2005, 1:36 PM   #25
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Quote:
Originally Posted by Cerulean
nor was I angry because I had opposing views to someone else in a discussion
I guess I got the wrong impression.

Quote:
Originally Posted by uman
By the way you have to admit "gimp" is a horrible name for a piece of software.
LOL I know but it's an abriviation, BTW I got over it because I've seen worst .
Now I use Ubuntu Linux 30% of the time and the names don't bother me much anymore. Honestly, if Linux has more real games (Day of Defeat), I would use it 60% of the time.
OpenLoop is offline   Reply With Quote
Old Aug 2nd, 2005, 10:10 AM   #26
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
Quote:
Originally Posted by darkone916
Does it have any side effects using "using namespace std; ?
It's not recommended to use "using namespace std;" in header files.
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Old Aug 2nd, 2005, 10:49 AM   #27
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
This was originally posted(not here) by grumpy
A common misunderstanding of the using directive and namespaces is shown in the following example;
[php]
#include <iostream>
using namespace std;

class Foo
{
// various other details

friend ostream & operator<<(ostream &, const Foo &);
};

int main()
{
Foo x;
cout << x;
}
[/php]
Most novices believe that the above will work, and output the object x to the standard stream std::cout. Even worse, some text books (which I won't name) encourage that belief. The result, however, is usually a compile time error. Worse still, some compilers also get it wrong, and don't complain---leaving a user mystified about why x is not output to standard output.

This example is problematical because the "using namespace" directive does not interact with the friend declaration (except with some buggy compilers) in the "obvious" way. The friend declaration is actually equivalent to
[php]
friend ::ostream &operator<<(::ostream &, const Foo &);
[/php]
whereas the programmer (because they have used the "using namespace" directive) thinks it is "obviously" equivalent to;
[php]
friend std::ostream &operator<<(std::ostream &, const Foo &);
[/php]
The first form has actually (implicitly) declared a type named ostream in the (unnamed) global namespace, and then declared an operator<<() that works with that implicitly declared type. The problem is, the type ::ostream is completely distinct from std::ostream. When we come to use it, in the line
[php]
cout << x;
[/php]

the compiler realises that cout is actually std::cout (thanks to the using directive) and then looks for an implementation of the corresponding operator<<() that works with a std::ostream on the left hand side and a Foo on the right. Our function "::ostream &operator<<(::ostream &, const Foo &)" does not satisfy that search, so a compile time error occurs.

In practice, to make the above example work, I would suggest never employing the "using namespace" directive in a header file or before any class declaration. Instead, I would do this;
[php]
#include <iostream>

// the following may be in a header file
class Foo
{
// various other details

friend std::ostream & operator<<(std::ostream &, const Foo &);
};

// OK, in our executing code we want to be lazy

using namespace std;

int main()
{
Foo x;
cout << x;
}
[/php]
This form also (thankfully) works as intended, even with compilers out there that handle the first form incorrectly.
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Old Aug 2nd, 2005, 11:53 AM   #28
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
hmm... interesting
OpenLoop is offline   Reply With Quote
Old Aug 2nd, 2005, 12:12 PM   #29
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Thanks for bringing part of that over, Infogeek. That was a contribution that Grumpy made that was misappropriated and attached to another's name....
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 2nd, 2005, 12:57 PM   #30
darkone916
Hobbyist Programmer
 
darkone916's Avatar
 
Join Date: Jul 2005
Location: Oman
Posts: 125
Rep Power: 4 darkone916 is on a distinguished road
Send a message via MSN to darkone916
i am too novice to understand the explanation...
but as u are more experienced wat do u advice me???
__________________
From the bottom of the stone steps...
...i'm calling still.
darkone916 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:05 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC