【发布时间】:2014-02-18 10:00:37
【问题描述】:
我有一个接口类:
Class IOperand
{
virtual ~IOperand() {};
virtual std::string getType() const = 0;
}
我有几个像这样的继承类:
class Int8: public IOperand
{
public:
Int8(int8_t _value = 0);
virtual ~Int8() {};
virtual std::string getType() const;
int8__t getValue() const;
private:
int8_t _value
}
我在 IOperand 类型上使用指针,但我需要使用 getValue() 成员函数。 如何根据 getType() 的返回(返回包含目标子类名称的字符串)将 IOperand 类型对象转换为子类类型对象?
【问题讨论】:
标签: c++ class c++11 casting type-conversion