#include using namespace std; class Matrix { int sizex; int sizey; double * data; public: int size_x() const { return sizex; } int size_y() const { return sizey; } double get(int i, int j) { return data[i*sizey + j]; } }; class ThoroidalMatrix : public Matrix { double get(int i, int j) { i = i % size_x(); j = j % size_y(); return Matrix::get(i, j); } }; class Base { public: void foo() { cout << "Base::foo()" << endl; } }; class Derived : public Base { public: void foo() { cout << "Derived::foo()" << endl; } }; int main() { Derived d; d.foo(); }