I'm compiling a 3rd party code (which is given as a VS solution) to a static library. This code has one class which is for simplification looks like this:
Sample.h:
class Sample
{
public:
Sample();
~Sample();
void Foo();
private:
// some private members.
};
Sample.cpp:
Sample::Sample()
{
}
Sample::~Sample()
{
}
void Sample::Foo()
{
//Do something...
}
This class compiles to a static library Sample.lib
Now in my main program I want to initiate an object of Sample:
MyFile.cpp:
#include "Sample.h"
//some code.
Sample* sample = new Sample();
//some code
and at some point when the program continues I'm getting a crash. The place where it crashes isn't consistent:
Unhandled exception at 0x770A0BFE (ntdll.dll) in MyApplication.exe: 0xC0000005: Access violation reading location 0xFFFFFFF8.
But when I put the Sample class in a wrapper class (in the same solution of the static lib): Wrapper.cpp:
class Wrapper
{
public:
Wrapper()
{
_sample = new Sample();
}
~Wrapper()
{
delete sample;
}
void Foo()
{
_sample->Foo();
}
private:
Sample* _sample;
}
and then initialize the Wrapper class in my program:
MyFile.cpp:
#include Sample.h
//some code.
Wrapper* wrapper = new Wrapper();
//some code
It works well and I'm not getting any crash.
Does anybody has a clue? Thanks!