Demo entry 6349575

derived.cpp

   

Submitted by saif on Feb 21, 2017 at 17:36
Language: C++. Code size: 947 Bytes.

// The base class
class Base {
private:
    int someNumber_;
public:
    void printNumber(){
        cout << "Printing number from base " << someNumber_ << endl;
    }
    virtual void func1(){
        cout << "printing from base::func1" << endl;
    }
    virtual void func2(){
        cout << "Printing from base::func2" << endl;
    }
    virtual void func3(){
        cout << "Printing from base::func3" << endl;
    }
};
// class devived1
class Derived1 : public Base {
public:
    void func1(){
        cout << "printing from Derived::func1" << endl;
    }
    virtual void func3(){
        cout << "Printing from base::func3" << endl;
    }
};
//class derived2
class Derived2 : public Base {
public:
    void func2(){
        cout << "printing from Derived::func2" << endl;
    }
};

int main(){
    Derived1 d1;
    Base &b = d1;
    b.printNumber();
    b.func1();
    b.func3();
    return 0;
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).