namespace

im creating header file. what code should i use if i want my header file use using namespace . i mean i want to change the "std" into other.
ex:
1
2
using namespace aw;
aw::myheader(asdfasdf);
Last edited on
mutexe i dont get it :(
You need to put all of your code inside the namespace in order to use it.

How to define the namespace is defined in the stackoverflow article mutexe sent:

ie. Your header file should look like this

myclass.h
1
2
3
4
5
6
7
8
namespace aw {
  class myClass() {
    public:
      myClass();
      int foo();
      //more stuff goes here as needed...
  };
}


Then your source file (if you aren't putting everything into your header file) should look like this:

myclass.cpp
1
2
3
4
5
#include "myclass.h"
using namespace aw;
myClass::myClass() { ... };

int myClass::foo() { ... };


Then anywhere else you want to use myClass, you can either tell the code to use that namespace, or (if you are already using another namespace) you can define it explicitly.

aw::myClass myInstance;
Actually... the consensus on stackoverflow seems to be defining the source file as such:

1
2
3
4
5
6
#include "myclass.h"
namespace aw { 
    myClass::myClass() { ... };

    int myClass::foo() { ... };
}
I see... in my header file I created I have to put all my code inside a namespace? So I can perform them using aw::abc By using using namespace aw; in cpp.
In 2nd snippet what do you mean on line 3?
It's a constructor.
Hehe I see im just confused thank you
Topic archived. No new replies allowed.