我有一个类,当我尝试在头文件中添加以下声明时:
bool m_DeviceIDs[100];
我遇到了分段错误。 有什么想法吗? 整个班级标题:
class Protocol
{
vector<ProtocolDevice*> _DeviceProtocols;
vector<Device>* _Devices;
Helper _Helper;
vector <unsigned char> m_MessageToSend;//xml messages to send
bool m_LockDevices;
//bool m_DeviceIDs[100];
unsigned int GetVacantID();
public:
Protocol(void){};
Protocol(vector<Device>* devices);
~Protocol(void);
void RemoveDevice(int DeviceID);
void AddDevice(Device device);
bool SendPing( int DeviceID);
bool GetInputStatus( int DeviceID);
void GetLowLevelConfiguration(int DeviceID);
bool ActivateOutput(char outputID, bool state, int DeviceID);
bool ActivateBSUHF(unsigned char state, int DeviceID);
bool ActivateUnitLF(unsigned char state,int DeviceID);
void StartDeviceListeners();
void WriteMessageToDevice(int DeviceID, unsigned char* message, int length);
vector<unsigned char> CollectDataFromDevice(int DeviceID,int dataLength);
int GetDeviceAvailableDataLength(int DeviceID);
void RefreshServerDetails(int DeviceID, string host, int port,int reconnectInterval);
void ReconnectHost(int DeviceID);
void SendVersion(int,bool);
void StartListentoDevice(int DeviceID);
void StopListenToDevice(int DeviceID);
bool SendSetLowLevelConfiguration(LowLevelConfiguration llConfig, int WaitAckMS, bool FromBaseToLocator,int DeviceID);
bool OperateExciterRead(char operation, unsigned int ReaderID, int Retries,int DeviceID);
bool RequestConfigurationFromLocator(int ReaderID,int TimeOut, int Retries,int DeviceID);
void SendXMLMessage(unsigned char opcode, vector<unsigned char> XMLData,unsigned int MessageID, unsigned int SourceID, unsigned int DestID);
void Mute(int Length, int DeviceID);
};
答案 0 :(得分:1)
您所显示的代码没有任何问题,但您可能需要尝试使用std::bitset代替bool
数组,因为它更具有多种功能和空间效果,例如:
#include <bitset>
std::bitset<100> m_DeviceIDs;