环境:Linux C++ / Qt 4x
我不明白为什么下面的downcast返回NULL?我在下面粘贴了基类和派生类。
提前感谢任何提示或建议。
-埃德
void MainWindow::onRtledaEventHandler(fes::EventArgs eventArgs)
{
// This cast returns a NULL ?
fes::AtsCommandEventArgs* atsCommandEventArgs = dynamic_cast<fes::AtsCommandEventArgs*>(&eventArgs);
}
/// The base class for containing event arguments sent to clients using boost::signals2
class EventArgs
{
public:
EventArgs() {}
EventArgs(RtledaEventType eventType) :
m_eventType(eventType) {}
EventArgs(const EventArgs& eventArgs) :
m_eventType(eventArgs.m_eventType) {}
virtual ~EventArgs() {}
/// The type of event this is
RtledaEventType eventType() const { return m_eventType; }
protected:
RtledaEventType m_eventType;
};
// Derived class I am trying to upcast to
class AtsCommandEventArgs : public EventArgs
{
public:
/// \param [in] lraddsPacketError LRADDS oacket error structure
/// \sa fes::StructPacketStats_t packetStats
AtsCommandEventArgs(fes::AtsCommand atsCommand, std::string messageBuffer, std::string details) :
EventArgs(RtledaEventTypeAtsCommand),
m_atsCommand(atsCommand),
m_messageBuffer(messageBuffer),
m_details(details) {}
AtsCommandEventArgs(const AtsCommandEventArgs& AtsCommandEventArgs) :
EventArgs(AtsCommandEventArgs),
m_atsCommand(AtsCommandEventArgs.m_atsCommand),
m_messageBuffer(AtsCommandEventArgs.m_messageBuffer),
m_details(AtsCommandEventArgs.m_details) {}
AtsCommandEventArgs() {}
~AtsCommandEventArgs() {}
fes::AtsCommand atsCommand() const { return m_atsCommand; }
std::string messageBuffer() const { return m_messageBuffer; }
std::string details() const { return m_details; }
private:
fes::AtsCommand m_atsCommand;
std::string m_messageBuffer;
std::string m_details;
};
提前感谢您的任何提示或建议,
-埃德