class Wrap
{
CRITICAL_SECTION cs_;
public:
Wrap() { InitializeCriticalSection(&cs_); }
~Wrap() { DeteteCriticalSection(&cs开发者_JS百科_); }
Wrap & operator=(const Wrap& rhs) { return *this; }
}
int main()
{
std::vector<Wrap> v;
v.push_back(Wrap()); //Memory error.
}
Please tell me what lead the error and how can I fix it.
James was right in his comment. Try this:
class Wrap
{
CRITICAL_SECTION cs_;
public:
Wrap()
{
InitializeCriticalSection(&cs_);
}
Wrap(const Wrap&)
{
InitializeCriticalSection(&cs_);
}
~Wrap()
{
DeleteCriticalSection(&cs_);
}
};
Such things can be easily detected with AppVerifier from Debugging tool for windows.
Good luck!
精彩评论