Boost共享指针初始化 [英] Boost shared pointer initialization

查看:148
本文介绍了Boost共享指针初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C ++的初学者。我有以下问题。在MevisPatientModel类中定义:

I am pretty a beginner in C++. I have following problem. In the class MevisPatientModel I defined:

typedef boost::shared_ptr<egMevisPatientModel> Ptr_t;



Then I "defined" the variable:

egMevisPatientModel::Ptr_t v_PatientModel;

现在,当我尝试访问MevisPatientModel类的getType函数时:

Now when I try to access the getType function of the class MevisPatientModel :

v_PatientModel->getType()

...我收到以下讯息:

...I'm getting following message:


声明失败! ... shared_ptr.hpp表达式px!= 0

Assertion failed! ...shared_ptr.hpp Expression px!= 0

我的意图是指针未初始化。现在我知道,这里有很多答案,适合我的问题。但正如我所说,我是一个初学者。说实话我不是这些答案明白。请帮助我,给我一个明确和具体的答案我的问题。非常感谢。

My intention is that the pointer wasn't initialized. Now I know that here are many answers which would "fit" to my question. But as I said, I am a beginner. To be honest I don't these answers understand. Please help me and give me a clear and specific answer to my problem. Thank you very much.

Greets,Marco

Greets, Marco

推荐答案

使用 new 创建动态对象,并将生成的指针分配给 shared_ptr

You need to create an dynamic object with new and assign the resulting pointer into the shared_ptr:

egMevisPatientModel::Ptr_t v_PatientModel(
    std::make_shared<egMevisPatientModel>());

这篇关于Boost共享指针初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆