I
Immortal Nephi
What happen if you want to use same function name? Same function
names in other header files will be conflict.
For example
// Header1.h
#include <windows.h> // Microsoft uses a lot of macros.
namespace Header1 {
#undef funcName // only for example like Microsoft’s funcName()
void funcName() {…}
}
// Header2.h
namespace Header2 {
void funcName() {…}
}
#include “Header1.h”
#include “Header2.h”
int main() {
Header1::funcName();
Header2::funcName();
return 0;
}
Namespace is the answer, but C++ Compiler will fail to compile.
Why? Header files might have same function name as macros such as
Microsoft uses a lot of macros. You will have to write “#undef
funcName” before either same funcName functions in different
namespaces will work.
But what? You may need to use Microsoft’s functions outside
namespace. You can’t undefined them. What is the alternation?
Rename your function names inside namespace?
names in other header files will be conflict.
For example
// Header1.h
#include <windows.h> // Microsoft uses a lot of macros.
namespace Header1 {
#undef funcName // only for example like Microsoft’s funcName()
void funcName() {…}
}
// Header2.h
namespace Header2 {
void funcName() {…}
}
#include “Header1.h”
#include “Header2.h”
int main() {
Header1::funcName();
Header2::funcName();
return 0;
}
Namespace is the answer, but C++ Compiler will fail to compile.
Why? Header files might have same function name as macros such as
Microsoft uses a lot of macros. You will have to write “#undef
funcName” before either same funcName functions in different
namespaces will work.
But what? You may need to use Microsoft’s functions outside
namespace. You can’t undefined them. What is the alternation?
Rename your function names inside namespace?