class base
{
int a, b;
public:
bool valid();
{
bool ok = false;
if (a > 5 && a < 10 && b > 2 && b < 8)
ok = true;
return ok;
}
};
class derived : public base
{
int a;
public:
bool valid();
{
bool ok = false;
if (a < 8 && a > 15 && // call base's class valid method;
ok = true;
return ok;
}
};
如何在派生类有效方法中调用基类有效方法?
答案 0 :(得分:0)
在base::valid()
班级代码中的任意位置使用derived
。
答案 1 :(得分:0)
class derived:public base
{
int a;
public:
bool valid();
{
bool ok= false;
if(a<8 && a>15 && base::valid()) //call base's class valid method;
^^^^^^^^^^^
side note: think about changing this condition
probably a>8 && a<15
ok = true;
return ok;
}
};