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
  • 90,891
  • 40
  • 158
  • 247
Karedia Noorsil
  • 400
  • 3
  • 8
  • 19

2 Answers2

0

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

Kristian D'Amato
  • 3,876
  • 8
  • 42
  • 67
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
  • 28,488
  • 8
  • 76
  • 116