开发者

Why does .NET dislike this C++/CLI template function?

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().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜