수정할 수없는 struct simple_instr이 있습니다. 그래서 같이 그것에서 파생 된 유형을 생성 :포인터가 파생 된 유형의 인스턴스를 가리키는 지 어떻게 알 수 있습니까?
struct ComplexInstruction : simple_instr
{
ComplexInstruction(const simple_instr& simple) : simple_instr(simple)
{
}
bool isHead;
bool isTail;
bool isPreHeader;
};
내가 simple_instr의 인스턴스가 실제로 ComplexInstruction인지 말할 수 있어야합니다.
ComplexInstruction comInstr = *current; // current is a pointer to a simple_instr
ComplexInstruction* cInstr = &comInstr;
내가
ComplexInstruction* cInstr = static_cast<ComplexInstruction*>(current);
를 사용하여, 그것이 null 말았 경우 확인했지만, 문제는 캐스트는 항상 성공할이며, cInstr가 null로 동일 결코 : 나는과 같이 ComplexInstructions을 만들 수 있습니다.
이 작업을 수행하는 올바른 방법은 무엇입니까?
기본 클래스는 다형성입니까? (즉, 가상 멤버 함수가 있습니까?) –
아니요. 불행히도 – Megatron