VS2010 C++ - 问题基于类指针到派生类指针
我使用 VS2010 和 C++,使用供应商库来连接他们的 USB 工业相机。
该库有一个名为 GrabberSinkType
的数据流接收器基本抽象类,它的派生类之一是 MediaStreamSink
,它负责将流写入视频文件。 MediaStreamSink
(不是基类的虚拟函数)支持的方法之一是 getFilename()
,它仅返回正在写入的文件的名称。
处理流的主要 Grabber
类有一个方法 getSinkTypePtr()
,该方法返回指向当前使用的接收器的指针,定义为 smart_ptr
。
我需要做的是检查是否是 MediaStreamSink,如果是,则获取文件名。我无法让它编译。检查它是否是媒体流类型后,我所做的就是
CString SinkPath = dynamic_cast<tMediaStreamSinkPtr>(m_cGrabber.getSinkTypePtr())->getFilename().c_str();
(tMediaStreamSinkPtr
的类型定义为smart_ptr
)。这会导致错误 2680:
“错误 C2680:'DShowLib::tMediaStreamSinkPtr':dynamic_cast 的目标类型无效 目标类型必须是对已定义类的指针或引用”
我已经尝试了我能想到的动态强制转换、静态强制转换、旧式强制转换的所有可能组合,虽然错误发生了变化,但我无法编译它。
我显然不知道不知道我在这里做什么,如何获取指向派生类的指针并成功调用其 getFilename()
方法?
Using VS2010 and C++, I am using a supplier library to interface to their USB industrial camera.
The library has an base abstract class for data stream sinks called GrabberSinkType
, and one of derived classes from that is MediaStreamSink
which deals with writing streams to video files. One of the methods supported by MediaStreamSink
(not a virtual function of the base class) is getFilename()
which simply returns the name of the file being written to.
The main Grabber
class which handles streaming has a method getSinkTypePtr()
, which returns a pointer to the sink in current use, defined as smart_ptr<GrabberSinkType> getSinkTypePtr() const;
.
What I need to do is check if is a MediaStreamSink, and if so, get the filename. And I cannot get it to compile. Having checked if it is a media stream type, all I am doing is
CString SinkPath = dynamic_cast<tMediaStreamSinkPtr>(m_cGrabber.getSinkTypePtr())->getFilename().c_str();
(tMediaStreamSinkPtr
is typedef'd assmart_ptr<MediaStreamSink>
). This results in error 2680:
"error C2680: 'DShowLib::tMediaStreamSinkPtr' : invalid target type for dynamic_cast
target type must be a pointer or reference to a defined class"
I have tried every possible combination of dynamic casts, static casts, old style casts I can think of, and whilst the error changes, I cannot get it to compile.
I clearly don't know what I'm doing here, how do I get a pointer to the dervied class and successfully call its getFilename()
method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论