Good day. Using the example of this, I want to understand how to make changes to a function of a class-successor. When calling class A, it should be 4, when calling B, it should be 8, but the output in both classes is 4. I can’t figure out how to fix the error.
#include <iostream> using namespace std; class A { public: int calculate() { return 2 * 2; } void print() { cout << calculate() << endl; } }; class B :public A { public: int calculate() { return 2 * 2 * 2; } }; void main() { A one; one.print(); B two; two.print(); }