Sorry if this was asked already, but I had a hard time searching for destructor and access violation =)
Here's C++ pseudo-code the scenario:
In DLL1 (compiled with /MT)
class A
{
public:
virtual ~A() <== if "virtual" is removed, everthing works OK
{
}
}
class B : public A
{
public:
__declspec( dllexport ) ~B() // i did try without exporting the destructor as well
{
} <== Access Violation as it returns (if fails in assembly at delete operator...)
}
In DLL2 which links to DLL1
main()enter code here
{
B* b = new B();
delete b; <== Access Violation
}
What is going on? Am I having a brain shart? If I make A's destructor non-virtual, everything works OK - even A and B's destructor get called (as if A's destructor was virtual - is this due to the fact that it's public?).
My main question though - is why is there an access violation when the base classe's destructor is declared as virtual?