开发者

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

开发者 https://www.devze.com 2022-12-22 06:33 出处:网络
In a plain vanilla WinForms app (C++/CLI, set to /clr), I have the following template function, flagged as \"unmanaged\":

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

精彩评论

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

关注公众号