使用std :: map作为本地成员的内存访问冲突

时间:2017-10-10 11:31:03

标签: c++ stdmap

在调用select se.scheduledate, pd.accountnumber, pd.firstname, pd.middleinitial, pd.lastname, pd.address1, pd.address2, pd.city, pd.state, pd.zipcode, pd.dateofbirth, pd.sex, pd.hometelephone, case when i.mnemonic = pip.insurance1mnemonic then pip.insurance1name else pip.insurance2name end, case when i.mnemonic = pip.insurance1mnemonic then pip.insurance1policynumber else pip.insurance2policynumber end, case when i.mnemonic = pip.insurance1mnemonic then pip.insurance1policygroupnumber else pip.insurance2policygroupnumber end, case when i.mnemonic = pip.insurance1mnemonic then pip.insurance1guarantorfirstname else pip.insurance2guarantorfirstname as insuredfirstname end, case when i.mnemonic = pip.insurance1mnemonic then pip.insurance1guarantormiddleinitial else pip.insurance2guarantormiddleinitial as insuredmiddleinitial end, case when i.mnemonic = pip.insurance1mnemonic then pip.insurance1guarantorlastname else pip.insurance2guarantorlastname as insuredlastname end, case when i.mnemonic = pip.insurance1mnemonic then pip.insurance1guarantoraddress1 else pip.insurance2guarantoraddress1 as insuredaddress1 end, case when i.mnemonic = pip.insurance1mnemonic then pip.insurance1guarantoraddress2 else pip.insurance2guarantoraddress2 as insuredaddress2 end, case when i.mnemonic = pip.insurance1mnemonic then pip.insurance1guarantorcity else pip.insurance2guarantorcity as insuredcity end, case when i.mnemonic = pip.insurance1mnemonic then pip.insurance1guarantorstate else pip.insurance2guarantorstate as insuredstate end, case when i.mnemonic = pip.insurance1mnemonic then pip.insurance1guarantorzipcode else pip.insurance2guarantorzipcode as insuredzip end, case when i.mnemonic = pip.insurance1mnemonic then pip.insurance1guarantordateofbirth else pip.insurance2guarantordateofbirth as insureddob end, case when i.mnemonic = pip.insurance1mnemonic then pip.insurance1guarantorsex else pip.insurance2guarantorsex as insuredsex end, case when i.mnemonic = pip.insurance1mnemonic then pip.insurance1guarantortelephonenumber else pip.insurance2guarantortelephonenumber as insuredhomenumber end, i.eligibilitypayornumber from patientdemographics pd inner join patientinsuranceprofiles pip on pd.accountnumber = pip.patientaccountnumber inner join scheduleentry se on pip.patientaccountnumber = se.patientaccount inner join insurances i on i.mnemonic in (pip.insurance1mnemonic, pip.insurance2mnemonic) where datediff(d, getdate(), scheduledate) = 1 and pip.activeflag = 1 order by scheduledate asc 中的方法m_Lights=tmp;期间,我在行v_init()上发生内存访问冲突错误。不应该在Algo::Init()的实例化时创建地图m_Lights吗?为什么我有这个错误?

m_LightsManager

3 个答案:

答案 0 :(得分:2)

如果Light不是trivially-copyable,那么

std::memset(&tL,0,sizeof(Light));

未定义的行为。这可能是导致错误的原因。

答案 1 :(得分:1)

除了Vittorios回答:在Light的构造函数中进行所有初始化,而不是依赖于外部memset调用。并且不要在C ++中使用std::memset来初始化一个语句中对象的所有成员变量,为每个变量明确地执行它(通常使用简单赋值;在C ++ 11中,即使在声明中也可以这样做/ header,恕我直言所属的地方。)

原因:可以派生Light,并且基类定义自己的数据,通过鲁莽地使整个对象归零来覆盖它。

答案 2 :(得分:0)

我解决了错误,问题来自于软件的其他部分中的错误声明指针,该对象与对象m_LightsManager所在的内存空间重叠,