腾讯云
开发者社区
文档
建议反馈
控制台
登录/注册
首页
学习
活动
专区
圈层
工具
MCP广场
文章/答案/技术大牛
搜索
搜索
关闭
发布
文章
问答
(9999+)
视频
沙龙
3
回答
auto_ptr
和dynamic_pointer_cast
c++
、
boost
如果我想在shared_ptr中使用
dynamic_cast
,我可以使用dynamic_pointer_cast。如果我希望强制转换
auto_ptr
,我应该使用什么?我假设如下所示
的
内容。struct B : A { };
auto_ptr
<A> base( ... );我正在对共享
浏览 2
提问于2011-07-05
得票数 4
回答已采纳
5
回答
为什么
这个
auto_ptr
的
dynamic_cast
会
失败
?
c++
、
casting
-1) {} return b; std::
auto_ptr
<A> a = new A(); 错误:无法
dynamic_cast<
浏览 0
提问于2009-02-06
得票数 6
回答已采纳
2
回答
将
auto_ptr
<Base>转换为
auto_ptr
<Derived>
c++
、
casting
、
auto-ptr
.; } using namespace std;
auto_ptr
<Circle> aC(new Circle); wcout << aS->GetName() << L'\t' << static_cast<
auto_ptr
<Circle>>(aS)->GetRadius() <<endl;
浏览 2
提问于2011-12-20
得票数 0
回答已采纳
2
回答
当“新”表达式中
的
指针被传递给
dynamic_cast
时,我如何跟踪这种情况?
c++
、
visual-c++
、
memory-management
、
new-operator
、
smart-pointers
最近,我在回顾一些旧代码时发现了以下内容:除了这段代码在有效情况下毫无意义(在有效情况下,class Derived是从class Base派生
的
,不需要
dynamic_cast
)之外,还有一个对象所有权问题。无论出于何种原因,如果
dynamic_cast
返回空指针,则
auto_ptr
将不会绑定到创建
的</e
浏览 0
提问于2011-03-31
得票数 1
回答已采纳
3
回答
确定由工厂方法返回
的
对象
的
类(错误:函数不使用1个参数)
c++
、
inheritance
、
factory-pattern
我有一个factorymethod,它要么返回baseclass
的
对象,要么返回derivedclass (baseclass
的
派生类)
的
对象。派生类有一个接受一个参数
的
方法virtual void foo(int x)。然而,baseclass没有任何参数
的
virtual void foo()。在我
的
代码中,工厂方法返回一个类型为bar
的
指针,该指针明确指向类derivedclass
的
对象。但是,由于只有在运行时才知道这一点,所以我看到一个编译器错误
浏览 2
提问于2013-10-18
得票数 1
回答已采纳
1
回答
从核心转储中识别
auto_ptr
背后
的
具体对象类型
c++
、
gdb
、
postmortem-debugging
我有一个
auto_ptr
<IFoo>,其中IFoo是一个只包含纯虚拟方法
的
接口。我得到
的
输出如下:$22 = (class martin::IFoo *) 0x7418 我真正想知道
浏览 4
提问于2012-10-17
得票数 5
回答已采纳
2
回答
std::bad_cast指针与引用情况
c++
、
exception
关于std::bad_cast异常,我注意到引用和指针似乎不是以同样
的
方式工作。例如:class B : public A {}; int main() A a;} int main() A* a = new A;
浏览 6
提问于2012-02-24
得票数 2
回答已采纳
3
回答
当
dynamic_cast
失败
时,这意味着什么?
c++
、
casting
、
runtime
、
kde-plasma
我在KDE软件中遇到过几个例子,其中
dynamic_cast
的
KPart在OS上
失败
了。我并不是一个C++专家,所以我甚至不知道从哪里开始调试这种情况。我在ktimetracker中看到了这种情况,最近(也是讨论得更多
的
)案例是Okular: 简而言之:Okular::Part类继承了Okular::ViewInterface类(作为列表中
的
最后一个父类然而,当代码检索Okular::Part*实例(part)时,
dynamic_cast
<Okular::ViewInterface
浏览 10
提问于2015-04-06
得票数 1
回答已采纳
1
回答
dynamic_cast
中
的
类型必须是指向完整类类型
的
指针或引用,或者是void *
c++
、
openscenegraph
我希望有人知道
为什么
下面的代码
会
失败
。我正在尝试从osg:: node * node对象中获取PositionAttitudeTransform (Openscenegraph )
的
一个实例。但是下面是粗体
的
编译器错误。node, osg::NodeVisitor* nv) // other code goes here osg::PositionAttitudeTransform* pat =
dynamic_cast
<osg::Posi
浏览 4
提问于2012-10-30
得票数 10
回答已采纳
5
回答
C++中
的
多态类型是什么?
c++
我在一篇文章中发现"static_cast用于非多态类型转换,
dynamic_cast
用于多态类型转换“。我知道int和double不是多态类型。这里
的
多态类型是什么意思?有人说,多态类型是指具有虚函数
的
基类。是那么回事吗?这是唯一
的
情况吗?还有什么?有没有人能给我更详细
的
解释?
浏览 0
提问于2010-01-09
得票数 38
回答已采纳
2
回答
投射对象
c++
、
casting
、
return
在我
的
代码中,我有一些类似的东西:{ { B, }; {{ { }{ { }我
的
MFC我如何编写这样
的
方法呢?{} 它返回适当
的<
浏览 3
提问于2012-04-29
得票数 0
1
回答
类型、动态浇铸(上播)和模板
templates
、
dynamic-cast
、
typeid
2)多态类型
的
dynamic_cast
:当RTTI关闭时,我得到一个警告(警告C4541:'
dynamic_cast
‘用于多态类型'CBase’和/GR-;不可预知
的
行为可能
会
导致)当我向上转换(派生到基本)时,不管有没有RTTI -编译顺利传递 我不明白
的
是,
为什么
当我做向上和RTTI关闭-我没有收到任何警告/错误!3)非多态类型
的
dynamic
浏览 6
提问于2010-05-10
得票数 0
4
回答
动态转换和静态转换
的
奇怪行为
c++
、
oop
、
casting
、
virtual-functions
、
dynamic-cast
你能解释一下
为什么
动态转换和静态转换是成功
的
吗?以及C++如何设法解决所需
的
虚拟函数?shape1->draw(); Shape* shape2 =
dynamic_cast
shape3->draw(); cout << "--- Dynamic Cast Square to Shape
浏览 0
提问于2012-05-04
得票数 4
回答已采纳
1
回答
C++隐式转换unique_ptr /
auto_ptr
到基类型不工作?
c++
、
templates
、
polymorphism
考虑以下代码: std::
auto_ptr
< B > b( new B() );}由于
auto_ptr
(参
浏览 2
提问于2021-06-01
得票数 0
1
回答
当目标指针不是基类类型时,
为什么
允许
dynamic_cast
为多态类生成空指针?
c++
、
polymorphism
、
c++17
、
dynamic-cast
、
nullptr
>{{{}}; { virt
浏览 0
提问于2020-01-21
得票数 2
回答已采纳
1
回答
如何使用TMemoryStrream编写和读取组件
c++
大约两周来,我一直在尝试使用TComponent
的
writecomponent方法在TMemoryStream对象上编写从writecomponent派生
的
任意类
的
对象,并使用readcomponent虽然我认为这是一项简单
的
任务,但我不能让它正常工作。实际上没有编译错误,但对象
的
属性没有正确加载。请帮我找出我做错了什么。这是我
的
代码片段。TCHAR* argv[]) Woman* FirstWoman = new Woman(NULL, 25, "Anjelina
浏览 0
提问于2016-06-10
得票数 1
4
回答
std::is_same和运算符编译错误||
c++11
、
g++
、
clang++
我不明白
为什么
下面的代码可以用Clang++编译,而不能用g++编译。true : (
dynamic_cast
<const Base*>(&object) !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
为什么
模板实例化不跳过测试
的
第二部分下面的代码还编译: return t
浏览 0
提问于2019-04-26
得票数 2
1
回答
使用const限定符将参数传递给模板函数时出错
c++
、
templates
、
constants
、
qualifiers
." << std::endl;{ const std::
auto_ptr
<int> ca; } 在第一种情况下,函数'func1‘接受一个泛型参数,而不考虑限定符,但是第二个情况是,当参数具有const限定符时,函数'func2’
会
失败
为什么
浏览 2
提问于2013-09-26
得票数 2
回答已采纳
2
回答
向下转换带有非多态类
的
dynamic_cast
,
为什么
它不能编译?
c++
、
class
、
dynamic-cast
、
downcast
public CBase { }; { CDerived d; CDerived* pd; pd =
dynamic_cast
<CDerived*>(&b); // wrong: base-to-derived<BaseOk*>(&d2);
浏览 0
提问于2013-03-14
得票数 2
回答已采纳
1
回答
将
auto_ptr
所拥有的指针存储在导致崩溃
的
向量中
c++
、
smart-pointers
、
auto-ptr
我很难使用
auto_ptr
进行崩溃。我知道您不能将
auto_ptr
存储在STL容器中。但是,如何将
auto_ptr
保存
的
指针值存储在向量中呢?如果
auto_ptr
删除了它们所指向
的
存储对象,那么存储这些内部指针
的
向量随后被销毁,将导致我
的
程序在向量Tidy_方法中崩溃。<ClassP> auto_pointer_1_; s
浏览 5
提问于2013-10-03
得票数 1
回答已采纳
点击加载更多
热门
标签
更多标签
云服务器
对象存储
ICP备案
云点播
腾讯会议
活动推荐
运营活动
广告
关闭
领券