#include iostreamhclass A private int a b;public Aint i int j a = i; b = j; void Moveint x int y a += x; b += y; void Show cout a b endl; ;class B private A public Bint i int j int k
There are some issues with this code:
-
The header file should be
instead of <iostream.h> as it is outdated. -
The main function should return an integer, so it should be defined as int main() instead of void main().
-
The Move() function in class A is not accessible in class B because of private inheritance. It should be changed to protected or public inheritance to allow access.
-
The Show() function in class B should call the Show() function in class A to display the values of a and b.
-
The function f1() in class B should call the Show() function in class A to display the values of a and b.
-
The cout statement in the Show() function of class B is missing the opening parenthesis.
Here's the corrected code:
#include
class A { protected: int a, b; public: A(int i, int j) { a = i; b = j; } void Move(int x, int y) { a += x; b += y; } void Show() { cout << "( " << a << ", " << b << " )" << endl; } };
class B : public A { public: B(int i, int j, int k, int l) : A(i, j) { x = k; y = l; } void Show() { A::Show(); cout << x << " ," << y << endl; } void fun() { Move(3,5); } void f1() { A::Show(); } private: int x, y; };
int main() { A e(1, 2); B d(3, 4, 5, 6); e.Show(); d.fun(); d.Show(); d.f1(); return 0;
原文地址: https://www.cveoy.top/t/topic/ffgf 著作权归作者所有。请勿转载和采集!