Question and code:
/* *copyright (c) 2016, Yantai University School of computer *all rights reserved. * File name: Zwj.cpp *: zhangqing * finish date: May 10, 2016 * Version number: v1.0 * * Problem Description: Read the program, write the results of the operation * Input Description: * Program output: */#include <iostream>usin G namespace Std;class a{protected: int a,b;public: A (int aa, int bb): A (AA), B (BB) {} void PrintA () { cout << "A:" <<a<< "\TB:" <<b<<endl; }}; Class b:public a{ int c;public: B (int aa, int bb, int cc): A (AA,BB), C (cc) {} void Printb () { cout< ;< "A:" <<a<< "\TB:" <<b<< "\TC:" <<c<<endl; }}; int main () { a A (); b b (2,3,4); A *p=&a; P->printa (); p=&b; P->printa (); P->PRINTB (); return 0;}
Error message:
Delete the line where the error occurred;
/* *copyright (c) 2016, Yantai University School of computer *all rights reserved. * File name: Zwj.cpp *: zhangqing * finish date: May 10, 2016 * Version number: v1.0 * * Problem Description: Read the program, write the results of the operation * Input Description: * Program output: */#include <iostream>usin G namespace Std;class a{protected: int a,b;public: A (int aa, int bb): A (AA), B (BB) {} void PrintA () { cout << "A:" <<a<< "\TB:" <<b<<endl; }}; Class b:public a{ int c;public: B (int aa, int bb, int cc): A (AA,BB), C (cc) {} void Printb () { cout< ;< "A:" <<a<< "\TB:" <<b<< "\TC:" <<c<<endl; }}; int main () { a A (); b b (2,3,4); A *p=&a; P->printa (); p=&b; P->printa (); return 0;}
Operation Result:
Cause of Error:
P is a pointer to a base class and cannot be called from a function inside a derived class.
11th Week reading procedure (5-4)