In a plain vanilla WinForms app (C++/CLI, set to /clr), I have the following template function, flagged as "unmanaged":
#pragma managed(push, off)
#include <string>
template< class c >
const c& test_alloc()
{
static c test_alloc;
return test_alloc;
}
#pragma managed(pop)
Then in main, I use it before Application::Run():开发者_如何学编程
test_alloc<int>(); // OK
test_alloc<std::string>(); // Fails: _CrtIsValidHeapPointer(pUserData)
static int test_alloc works fine, but static string test_alloc fails with the "you're corrupting the heap" error: _CrtIsValidHeapPointer(pUserData). Can anyone explain to me what's going on here?
The problem is actually presenting itself when I'm trying to use boost::filesystem::initial_path().
精彩评论