Thread: Namespace?

  1. #1
    Registered User
    Join Date
    Apr 2002

    Post Namespace?

    I was just wondering if someone could tell me what namespace is. How, when and why one should use it would be nice also

    Best Regards,

  2. #2
    Registered User
    Join Date
    Mar 2002
    a namespace is a device for limiting name clashes in large projects. You can think of it as a package in which "everything else" is held. Until you get beyond the basics of programming in C++ you don't have to worry about this too much. Once you start working on large projects with several development teams, etc., it is supposed to make life easier. The way it's defined is you have always been working in namespace std, but now you should explicitly declare it.

  3. #3
    #include <iostream>
    using namespace std;
    namespace cheese {
    	int x;
    namespace frog {
    	int x;
    int main(void) {
    	cout << "How old is your cheese?" << endl;
    	cin >> cheese::x;
    	cout << "How old is your frog?" << endl;
    	cin >> frog::x;
    	cout << "so you are trying to tell me your cheese is " << cheese::x << " years old?" << endl;
    	cout << "and your frog is " << frog::x << " years old?" << endl;
    	return 0;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. extern namespace?
    By Brafil in forum C++ Programming
    Replies: 2
    Last Post: 01-10-2009, 08:06 AM
  2. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. data validation & namespace
    By tiange in forum C++ Programming
    Replies: 4
    Last Post: 07-05-2005, 02:45 AM