What for are namespace?WHAT ABOUT SKYPE GROUP CHAT?

May 11, 2013 at 9:23pm


 
  No code here, just wondering what can i do with namespace? I saw a lot of strange uses of it,like use namespace life...:D


Also...
BEGGINNERS,WHAT ABOUT SKYPE CHAT GROUP?

BECAUSE SERIOUSLY...to do it alone is like - not just a little bit boring sometimes,but much longer,we may share some ideas,as we all are begginners and we want the same thing :)
If you are looking positive to this and you think it would be nice to have chat like this - add me in skype -> mantasxxl3

I would create it only then,if at least 5 people show that the idea is quite good.
Last edited on May 11, 2013 at 9:25pm
May 11, 2013 at 9:38pm
namespaces are so that you do not have the same variable/function name used twice.
ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>

namespace life1
{
    const unsigned int a = 5;
    void function( void )
    {
        std::cout << "This is the life1 namespace!" << std::endl;
        std::cout << "A from this namespace is = " << a << std::endl;
        std::cout << "------------------------------" << std::endl;
    }
}

namespace life2
{
    const unsigned int a = 10;
    void function( void )
    {
        std::cout << "This is the life2 namespace!" << std::endl;
        std::cout << "A from life1 is = " << life1::a << std::endl;
        std::cout << "A from this namespace is = " << a << std::endl;
        std::cout << "------------------------------" << std::endl;
    }
}

void function( const unsigned int a )
{
    std::cout << "This is not in a namespace!" << std::endl;
    std::cout << "A from function without namespace = " << a << std::endl;
    std::cout << "------------------------------" << std::endl;
}

int main( void )
{
    const unsigned int a = 1;
    function( a );
    life1::function();
    life2::function();

    std::cout << "A from main function is: " << a << std::endl;
    std::cout << "A from namespace life1 is: " << life1::a << std::endl;
    std::cout << "A from namespace life2 is: " << life2::a << std::endl;
    return( 0 );
}
This is not in a namespace!
A from function without namespace = 1
------------------------------
This is the life1 namespace!
A from this namespace is = 5
------------------------------
This is the life2 namespace!
A from life1 is = 5
A from this namespace is = 10
------------------------------
A from main function is: 1
A from namespace life1 is: 5
A from namespace life2 is: 10

Process returned 0 (0x0)   execution time : 0.025 s
Press any key to continue.


You can read up more on namespaces here
http://www.cplusplus.com/doc/tutorial/namespaces/
Topic archived. No new replies allowed.