![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#21 | ||
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
Quote:
Quote:
|
||
|
|
|
|
|
#22 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
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.
|
|
|
|
|
|
#23 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
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
![]() |
|
|
|
|
|
#24 |
|
Expert Programmer
Join Date: Dec 2004
Posts: 794
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#25 | ||
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
Quote:
Quote:
. 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. |
||
|
|
|
|
|
#26 | |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
Quote:
__________________
PFO - My daily dose of technology. |
|
|
|
|
|
|
#27 |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#28 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
hmm... interesting
|
|
|
|
|
|
#29 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#30 |
|
Hobbyist Programmer
|
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|