Reputation: 53
For example you have such situation:
1)Header file with some class definition that contain some member function (def.h).
2)That header is included into .cpp files with the same name that resides in a separate folders.
3)That .cpp files impements same function from def.h but in different way.
3)Then we include that header into some main.cpp and call function with multiple impementation and compile that whole project.
Question: will it compile without errors? What function implementation will be chosen?
Upvotes: 1
Views: 69
Reputation: 10155
Defining a function in two separate places violates One Definition Rule.
One and only one definition of every non-inline function or variable that is odr-used (see below) is required to appear in the entire program (including any standard and user-defined libraries). The compiler is not required to diagnose this violation, but the behavior of the program that violates it is undefined.
To have well-defined behavior, you should either:
Upvotes: 3