I have a solution in visual studio with two projects. The first project generates a static library. It has a macro set for the whole project, we'll call it 'ENABLE'. It also has a class as follows:
BadClass.h
class BadClass
{
public:
BadClass()
~BadClass()
private:
#ifdef ENABLE
std::mutex mutex1;
#endif
std::mutex mutex2;
}
BadClass.cpp
BadClass() { }
~BadClass() { }
The second project generates an application which references the first project and uses its generated library. Within one of its functions I create a local instance of BadClass which gets destructed at the end of scope. I do NOT define the matching preprocessor macro 'ENABLE' in this project. I get an exception in the destructor of a mutex.
My assumption was that the constructor & destructor are defined in the library and will behave as the library is setup to compile. However it seems the header being referenced in the application project is changing their behaviours and now they are trying to destruct something that is not there. I don't quite understand why though. Is the application allowed to override the layout? Have I inadvertently created a weird duplicate symbol (so I have two BadClasses; one with the second mutex, one without), or something else?