我有包類包含虛方法,我有延伸分組分類虛保護功能錯誤
Packet.h LogInRequest類文件
class Packet {
public:
Packet();
virtual ~Packet();
protected:
virtual char* toByte() = 0;
virtual void fromByte(char *d) = 0;
virtual Packet* handle() = 0;
short m_bodySize;
int64_t m_deviceId;
};
/*
* LogInRequestPacket
*/
class LogInRequestPacket: public Packet{
public:
LogInRequestPacket();
virtual ~LogInRequestPacket();
virtual char* toByte();
virtual void fromByte(char *d);
virtual Packet* handle();
};
Packet.cpp文件
#include "Packet.h"
Packet::Packet() {
// TODO Auto-generated constructor stub
}
Packet::~Packet() {
// TODO Auto-generated destructor stub
}
/*
* LogInRequestPacket
*/
LogInRequestPacket::LogInRequestPacket(){
printf("LogInRequestPacket is being created... \n");
}
LogInRequestPacket::~LogInRequestPacket(){
}
char* LogInRequestPacket::toByte(){
}
void LogInRequestPacket::fromByte(char *d){
}
Packet* LogInRequestPacket::handle(){
}
我試圖從這樣的工廠創建這個LogInRequestPacket
Packet *packet = m_packetFactory->createInstance(static_cast<PACKET_TYPES>(type));
packet->fromByte(pdata);
它似乎試圖調用受保護的虛擬fromByte函數而不是子類的fromByte函數。
我得到的線紅線在Packet.h文件包類範圍聲明「虛擬無效fromByte(字符* d)= 0」,並抱怨「......保護」
而且,它也抱怨與x在範圍內
packet->fromByte(pdata);
我該如何解決這個問題。在此先感謝...