Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 namespace
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Mazer




PostPosted: Tue Jun 24, 2003 9:32 am   Post subject: namespace

ok, honest to God, what the heck is a namespace? i see this just about everywhere i go, right under the includes and i just don't get why it's used. something to do with preventing naming conflicts in C++ apparently. but when would you get a naming conflict? and what would happen if you did get one? is the namespace part of the program always necessary?
Sponsor
Sponsor
Sponsor
sponsor
Catalyst




PostPosted: Tue Jun 24, 2003 12:45 pm   Post subject: (No subject)

its not necessary its just convinient

for example:

code:

using namespace std;

cout<<"Hello";



without the namespace it would be

code:

std::cout<<"Hello";
Mazer




PostPosted: Tue Jun 24, 2003 2:06 pm   Post subject: (No subject)

really? i've done it without namespace. in dev-c++ i just you cout without the std:: part in front and it worked fine
Catalyst




PostPosted: Tue Jun 24, 2003 2:10 pm   Post subject: (No subject)

some compilers will do the std namespace for you since its a standard
Tony




PostPosted: Wed Jun 25, 2003 11:56 pm   Post subject: (No subject)

ya, I had that same issue too... throughout the year I would not use namespace cuz it didn't appear to do anything, but sometimes I would get random errors for no reason and namespace would fix them Confused so now I use it Razz
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Asok




PostPosted: Thu Jun 26, 2003 1:07 am   Post subject: (No subject)

I use it, simply because I'm lazy so if I never use std big deal, and if I do then I don't have to worry about it, I just put it up at the top with my #include and #ifndef
UBC_Wiskatos




PostPosted: Mon Jun 30, 2003 10:13 pm   Post subject: (No subject)

Basically, using namespace std means that all functions under the scope of std don't have to be written like std::foo. It's a bit more complex than that, but basically, all the functions in the Standard Template Library are under the namespace std. So to access them, you go std::cout or whatever. Say you have another namespace, called boo, and it has a function called cout, you'd call it by going boo::cout. Now, when you say using namespace std, you say that when you type cout, it will automatically mean std::cout. Otherwise, the compiler will be like, did you mean the boo namespace, or the std namespace?
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: