I created two different header files, each containing a class with same names and each one is included on different cpp files, so the compiler does not complain about redefinition of them
They operate like two different classes, except when they have the same methods, with same name and same arguments, only one of them is called, for example:
//on first cpp:
#include "same1.h"
//...
SameName obj(int_value);
obj.ok(int_value);
obj.not_ok();
//on second cpp
#include "same2.h"
//...
SameName obj(float_value);
obj.ok(float_value);
obj.not_ok();
on both files, not_ok from same1.h is called, and of course it has not been initialized correctly
I know what the problem is and why this happens, I’m also familiar with Name mangling and that they both have the exact same name when compiled.
I just want to know that is it standard behavior of C++ or is it just how my compiler have implemented that, I mean, should all compilers do the same thing on this situation or not?
I should mention that I’m using gcc 4.7.1 on Debian Linux.
This is a violation of One Definitlion Rule and undefined behavior.