0
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;
    }
};

Hpw to call base class valid method in derived class valid method?

David G
  • 94,763
  • 41
  • 167
  • 253
Karedia Noorsil
  • 430
  • 3
  • 9
  • 21

2 Answers2

0

Use base::valid() anywhere within the derived class code.

Kristian D'Amato
  • 3,996
  • 9
  • 45
  • 69
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;

        }

};
4pie0
  • 29,204
  • 9
  • 82
  • 118