»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 10-13-2003, 04:12 PM   #1 (permalink)
Registered User
 
SpookyEddy's Avatar
 
Join Date: Oct 2001
Location: UK
Posts: 3,125
SpookyEddy is on a distinguished road
Kids Scoping namespace voodoo (c++)

Ok, so I am messing around with c++ and I noticed that the book I am using scopes the standard namespace like so...
Code:
#include <iostream>
using namespace std;

int main()
{
    //do some voodoo
    return 0;
}
However, a large number of the examples I have seen online opt for...
Code:
#include <iostream>

int main()
{
    using namespace std;
    //do some voodoo
    return 0;
}
So.. what is the prefered method and why?

I am new to this c++ stuff so be gentle.

Regards

ed

SpookyEddy is offline   Reply With Quote
Old 10-23-2003, 06:09 PM   #2 (permalink)
Registered User
 
Join Date: Apr 2002
Location: Georgia
Posts: 137
Jüš† ä gü¥ is on a distinguished road
My preferred method is

#include <iostream.h>

int main(){

//your code

return 0;
}

I think namespaces are worthless and ultimately just convolute the language more and create even more incompatibilities and bulkier code, but that's just me.

As far as actually using namespaces and where they are placed, I'd say to go for placing it on the outer scope as, that way, it will be accessible throughout the entire program and not just in function main
__________________
Jüš† ä €öm¶ù†Ê® §ÇÌÈñŒ mÅjÒ®
Jüš† ä gü¥ is offline   Reply With Quote
Reply




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
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 06:26 AM.