简体   繁体   English

从std :: make_shared到std :: shared_ptr的分配静默失败? (VS2012错误)

[英]Assignment from std::make_shared to std::shared_ptr fails silently? (VS2012 Bug)

EDIT: Renaming the global var did the trick. 编辑:重命名全局变量做到了。 The same was being reused in other CPP files in the same project. 同一项目中的其他CPP文件中已重复使用相同的内容。 The editor was "confusing" the variable, showing the content of another shared_ptr with the same name! 编辑器使变量“混乱”,显示了另一个同名的shared_ptr的内容!

Thanks for all who answered and tried to help ;) 感谢所有回答并尝试提供帮助的人;)


In VS2012 IDE, VS2010 compiler, Debug 在VS2012 IDE,VS2010编译器,调试

When assigning from make_shared, it doesn't work (shared_ptr stays nullptr). 从make_shared分配时,它不起作用(shared_ptr保持为nullptr)。

I can see in the debugger the class ctor was called. 我可以在调试器中看到名为ctor的类。

In the header file 在头文件中

    struct  ROLLWRKAREA  Workarea
    {
        short idLoc;
// ...
    ROLLWRKAREA(short idLocation=LS_NOWHERE) : 
        idLoc(idLocation),
// …
};
typedef std::shared_ptr<ROLLWRKAREA> LPROLLWRKAREA;

In My CPP -> 在我的CPP中->

static LPROLLWRKAREA pWA; // ...and pointer

BOOL CRollEx::OnInitDialog ()
{
         CMMDialog::OnInitDialog ();

    pWA = std::make_shared<ROLLWRKAREA>();

… pWA has empty (nullptr) after this line. …pWA在此行之后为空(nullptr)。

Is this expected? 这是预期的吗? Am I doing something stupid here? 我在这里做蠢事吗? Is there a workaround? 有解决方法吗? I'm trying to avoid using .reset(new ROLLWRKAREA()) 我正在尝试避免使用.reset(new ROLLWRKAREA())

Thanks in advance 提前致谢

In the Line 行中
pWA = std::make_shared<ROLLWRKAREA>(); you need to give something to make shared... 您需要提供一些共享的东西...
Until then, you get the most sensible you can expect: NULL 在那之前,您将获得最明智的期望:NULL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM