Namespaces

This is a discussion on Namespaces within the C++ Programming forums, part of the General Programming Boards category; I've never touched them and the book I have is really old and doesn't even mention them. I think they ...

  1. #1
    Señor Member
    Join Date
    Jan 2002
    Posts
    561

    Namespaces

    I've never touched them and the book I have is really old and doesn't even mention them. I think they are used to avoid confusion between naming of class functions, but how do you use them, and what is the syntax? Anyone care to explain? Thanks.

  2. #2
    Registered User InFeStEd-ArCh0n's Avatar
    Join Date
    Apr 2002
    Posts
    63
    Simple. Lets say you define two classes with the same name. Namespacing allows you to be able to differenciate between the two. For example: one::Class, two::Class. It's simple to do:

    Code:
    // one.h
    namespace one
    {
        char func(char);
        class String { ... };
    }
    
    // somelib.h
    namespace SomeLib
    {
        class String { ... };
    }
    You can now reference them as SomeLib::String and one::String.

    Get it?

    (For more information check out http://msdn.microsoft.com/library/de...namespaces.asp and http://msdn.microsoft.com/library/de...namespaces.asp)
    -Mike
    {InFeStEd-ArCh0n}

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Your old book didn't talk about them because namespaces are relatively new.

  4. #4
    Señor Member
    Join Date
    Jan 2002
    Posts
    561
    Yeah that's what I was implying.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Namespaces
    By the pooper in forum C Programming
    Replies: 8
    Last Post: 01-21-2005, 08:06 AM
  2. namespaces and friends
    By okinrus in forum C++ Programming
    Replies: 1
    Last Post: 03-27-2004, 07:47 AM
  3. custom namespaces
    By uvacow in forum C# Programming
    Replies: 2
    Last Post: 03-16-2004, 01:53 PM
  4. namespaces and static class members
    By ygfperson in forum C++ Programming
    Replies: 1
    Last Post: 07-06-2003, 08:55 PM
  5. namespaces
    By Mario in forum C++ Programming
    Replies: 3
    Last Post: 05-27-2002, 02:57 PM

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