Run Code  | API  | Code Wall  | Misc  | Feedback  | Login  | Theme  | Privacy  | Patreon 

inheritance test

//g++  5.4.0

#include <iostream>
using namespace std;

class number {
    private:
    double n;
    
    public:
    number():n(0){}
    number(double _n):n(_n){}
    
    double square() {
        return (this->n)*(this->n);
    }
    
    bool isPositive() {
        return (n>0);
    }
};

class positive_number : public number {
    private:
    double n;
    
    public:
    positive_number():n(0){}
};

int main()
{
    positive_number a;
    cout << a.square();
}
 run  | edit  | history  | help 0