读书人

怎么在子类函数中调用基类函数

发布时间: 2012-04-26 14:01:31 作者: rapoo

如何在子类函数中调用基类函数
要怎么调用 我用A::get()方式调用 显示错误为
the object has type qualifiers that are not compatible with the member function A::get()
这句话是什么意思 get()是double类型 而我用在子类的print()函数中 因为这个get()是virtual 在子类中有了新的定义
但是现在我只需要子类中的实现过程 要怎么调用

[解决办法]
class CBase
{
int m_base;
public:
CBase(){};
~CBase(){};

int get(){return m_base;};
};


class CTest:public CBase
{
int m_Test;
public:
CTest(){};
~CTest(){};

int get(){return m_Test;};

int CallBaseGet()
{
return CBase::get();
}
};

测试代码
CTest ff;
ff.CallBaseGet();

读书人网 >C++

热点推荐