Namespace?

This is a discussion on Namespace? within the C++ Programming forums, part of the General Programming Boards category; I was just wondering if someone could tell me what namespace is. How, when and why one should use it ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    4

    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,
    Purre

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    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
    Shadow12345
    Guest
    Code:
    #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, 07: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, 04: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21