我有两个类,如下面
class AppManagment : public MsgManagment{
string name;
int id;
void OnNewMsg(const Msg *msg);
};
class __declspec(dllexport) MsgManagment{
};
当我调用此函数时
void AppManagment::OnNewMsg(const Msg *msg){
id = msg->GetId();
name = msg->GetName();
}
行id = msg->GetId();
中的Id值不会插入到id变量
并在行name = msg->GetName();
中我得到一个例外:
ForexApplication.exe中0x63fcedac(msvcr90d.dll)的未处理异常:0xC0000005:访问冲突写入位置0x003f3fcd。
消息代码如下:
class CStartOfDayAck : public Messages::Msg
{
private:
std::string protocolName_;
uint8 Id_;
public:
enum {
code = 25,
};
CStartOfDayAck(Header *header = new ForexHeader(code)):Msg(header)
{
m_MessageName = "CStartOfDayAck";
numSession_ = 0;
}
Codecs::DataSource & deserialize(Codecs::DataSource & source)
{
if(header_->getLen()>sizeof(Id_))
{
protocolName_.resize(header_->getLen() - sizeof(ackId_));
source>>protocolName_;
} else {
throw std::exception("Empty protocolName");
protocolName_.clear();
}
source>>Id_;
return source;
}
Codecs::DataDestination & serialize(Codecs::DataDestination & destination) const
{
destination<<protocolName_;
destination<<numSession_;
return destination;
}
std::string GetName() const
{
return protocolName_;
}
uint8 GetId() const
{
return Id_;
}
virtual int type() const
{
return code;
}
virtual Serializable* clone() const
{
return new(CAck);
}
virtual void ApplyMsg(MsgManagment *)const;
};
我打电话给OnNewMsg就像在ApplyMsg中一样,如下所示:
void CStartOfDayAck::ApplyMsg(MsgManagment *Applay)const{
((App::AppManagment*)(Applay))->OnNewMsg(this);
}
我使用visual c ++ 2010
为什么会这样?