About namespaces

I want to manage my code, and force me to write namespace::myclass
(to read my code more easily).
OK.
I can write
1
2
3
4
5
namespace MYNM {
Myclass {};
};
Myclass {};
Myclass::Metod1(){};

So, method1 is not reachable. Why ? C++ does not undertand that if I put Myclas into the namespace is because I want to access to any method of this class ?

The solution is to write namespace MYNM { and a } at the end of my file.h. So every is accessible.

What is yout opinion ?
1
2
3
4
5
6
7
8
9
10
.h file
namespace MYNM {
  Myclass {};
}

.cpp file
namespace MYNM {
  Myclass::Myclass {}; //constructor
  Myclass::Metod1(){};
}
Why not all into one .h file ? I can not do so ?
I have read this article 3 times.
But .... I still does not know why I can have only a .h file ?
And does not understand what this article says about '
'h files are not compiled'
I'm a total c++ begginer and some concepts are beyond my comprehension.
Thanks
If you #include multiple times a header which contains non-template and non-inlined function definitions ( such as in your case ) you'll get some function redefinition errors
ok.
By the moment I understand :
Write the proto in .h files and then the real code into c.files ?
(I really feel that it means write twice some things)
Thanks
Yes, the purpose of header files is making visible what's inside a different source/binary file to be used in the current source file
Topic archived. No new replies allowed.