Let's say I have this physical structure:
/
+
| +
| +
| +
+
| +
| | +
| | +
| +
| +
These are the sources of libconflict, take a deep breath:
class B header in libconflict:
class B
{
public:
void bar();
protected:
int j_;
};
class B implementation in libconflict:
#include "conflict/B.h"
void B::bar()
{
std::cout << "B::bar" << std::endl;
}
class A header in libconflict:
# include "conflict/B.h"
class A : public B
{
public:
A();
private:
int i_;
};
class A implementation in libconflict:
#include "conflict/A.h"
A::A()
{
std::cout << "libconflict A is alive" << std::endl;
i_ = 51;
j_ = 47;
}
Now the sources of conflict, it is almost over:
class A header in conflicttest:
class A
{
public:
A();
void foo();
};
class A implementation in conflict:
#include "A.h"
A::A()
{
std::cout << "A is alive" << std::endl;
}
void A::foo()
{
std::cout << "A::foo" << std::endl;
}
and finally main.cpp:
#include "conflict/A.h"
int main()
{
B* b = new A;
b->bar();
return 0;
}
Phew ... I am using Visual Studio 2010 to create this solution. conflicttestis an executable file that is associated with a static library libconflict. This compiles like a charm, but, believe it or not, the output is:
A is alive
B::bar
The linker actually uses a symbol Afrom conflicttest, which is absolutely not Band, even worse, it can cause B::bar().
I'm lost, why does the compiler not complain?