具有虚拟继承的行中的c ++分段错误

时间:2015-10-12 12:44:34

标签: c++ inheritance virtual

我得到分段错误,gdb告诉我这个

Program received signal SIGSEGV, Segmentation fault.
0x0000000000418710 in IStatus::IStatus (this=0x6f2850, __vtt_parm=0x0, __in_chrg=<optimized out>)
    at DisplayWidgets/../SignalContainers/IStatus.hpp:13
13  class IStatus : public virtual IProcessable

当我做的时候

int signalStrength = 0;
GsmSignalContainer* SignalContainer = new GsmSignalContainer(signalStrength, radioIntegratorComm::GsmLineStatus::GLS_Idle);

有人可以告诉我发生了什么事吗?我几乎不能连续两次继承或者什么?

层次结构的顶部

 * IProcessable.hpp
 *
 *  Created on: Oct 08, 2015
 *      Author: patrykw
 */

#ifndef IPROCESSABLE_HPP_
#define IPROCESSABLE_HPP_

struct IProcessable
{
    virtual ~IProcessable() {};
};

#endif /* IPROCESSABLE_HPP_ */

中,删除:公共虚拟IProcessable使其编译得很好,添加构造函数不会改变任何东西,它只是将错误移动到构造函数的行。

/*
 * IStatus.hpp
 *
 *  Created on: Sep 22, 2015
 *      Author: patrykw
 */

#ifndef ISTATUS_HPP_
#define ISTATUS_HPP_

#include <displayController/SignalProcessor/IProcessable.hpp>

class IStatus : public virtual IProcessable
{
public:
    virtual ~IStatus() {}
};

#endif /* ISTATUS_HPP_ */

这是具有接口

的具体类
#ifndef GSMSIGNALCONTAINER_HPP_
#define GSMSIGNALCONTAINER_HPP_

#include "../../src_proto/RadioIntegrator.pb.h"
#include "IStatus.hpp"

class IGsmSignalContainer : public virtual IStatus
{
public:
    virtual radioIntegratorComm::GsmLineStatus LineStatus() const = 0;
    virtual int SignalStrength() const = 0;
};

class GsmSignalContainer : public virtual IGsmSignalContainer {
public:
    GsmSignalContainer(int signalStrength, radioIntegratorComm::GsmLineStatus lineStatus);

protected:
    radioIntegratorComm::GsmLineStatus _gsmLineStatus;
    int _signalStrength;

    //IGsmSignalContainer implementation
    radioIntegratorComm::GsmLineStatus LineStatus() const { return _gsmLineStatus; };
    int SignalStrength() const { return _signalStrength; } ;
};

#endif /* GSMSIGNALCONTAINER_HPP_ */

和实施

GsmSignalContainer::GsmSignalContainer(int signalStrength, radioIntegratorComm::GsmLineStatus lineStatus)
{
    _signalStrength = signalStrength;
    _gsmLineStatus = lineStatus;
}

0 个答案:

没有答案