top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the use of namespaces in C++ ?

0 votes
265 views
What is the use of namespaces in C++ ?
posted Dec 7, 2014 by Vikram Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

namespace is used to avoid name collision.

for Ex;

using namespace std;

that means, Below code has to use std library.
if you don't want to write namespace then you have to use (::) scope resolution operator.

answer Dec 8, 2014 by Chirag Gangdev
Similar Questions
0 votes

I am new to C+ and I wonder why this code compiles fine with g+ and MSVC:

 namespace t {

 class A {
 public:
 int i;
 };

 int b(int k, A a) {
 return k;
 }

 }

 int main()
 {
 t::A cl;
 return b(5, cl);
 }

I thought that b should not be visible from the main function.

+7 votes

In lot of C++ code in my company I see extern C code something like

extern "C"
{
    int sum(int x, int y)
    {
        return x+y;
    }
}

Please explain the significance of this?

+3 votes

Please provide some details on the static class variable, how it works and any example would be great.

...