Untitled

mail@pastecode.io avatar
unknown
plain_text
24 days ago
415 B
2
Indexable
Never
#include <iostream>

class A {
public:
    A() {
        someVirtualMethod();
    }
    void print() {
        std::cout << n;
    }
protected:
    virtual void someVirtualMethod() {
        n = 1;
    }
    int n;
};

class B : public A {
public:
    B() {}
private:
    void someVirtualMethod() override {
        onlyInB = 2;
    }
    int onlyInB;
};

int main() {
    B b = B();

    b.print();
    return 0;
}
Leave a Comment