Question: #include using namespace std; class A { protected: int a1, * aptr; public: A(int = 1); ~A(); virtual void Test() { cout < <

#include  using namespace std; class A { protected: int a1, * aptr; public: A(int = 1); ~A(); virtual void Test() { cout << " Testing Class A" << endl; } }; A::A(int a) { a1 = a; aptr = NULL; cout << "Constructor of A class "; } A::~A() { cout << "Destructor of A class "; delete[]aptr; } class B { protected: int b1; public: B(int = 2); ~B(); }; B::B(int b) { b1 = b; cout << "Constructor of B class "; } B::~B() { cout << "Destructor of B class "; } class C : public A, public B { private: const int c1; static int cTemp; public: C(int = 0, int = 3); void Test(); void Display(); }; int C::cTemp = 0; C::C(int x, int y) :c1(x), A(y) { cout << "Constructor of C class "; cTemp++; aptr = new int[y]; } void C::Display() { Test(); cout << "a1=" << a1 << "b1=" << b1 << "c1=" << c1; cout << " cTemp=" << cTemp << "aptr = "; for (int i = 0; i < a1; i++) cout << aptr[i] << " "; } void C::Test() { cout << " Testing Class C" << endl; for (int i = 0; i < a1; i++, b1++) aptr[i] = b1 + 5; } class D : protected C { private: int d1; int* dptr; public: D(int = 0, int = 0, int = 0); void Display(); void input(); ~D() { cout << "Destructor of D class "; delete[] dptr; } }; D::D(int m, int x, int y) :C(x, y) { cout << "Constructor of D class "; d1 = m; dptr = new int[d1]; } void D::Display() { C::Display(); cout << " d1=" << d1 << endl; } void D::input() { for (int i = 0; i < d1; i++) cin >> dptr[i]; } void temp(A* aptr) { aptr->Test(); } void main() { D dobj(2, 3, 4); temp(&dobj); }

There is a compile time error in the function temp. What is the reason of error? Explain how you will correct it.

void temp(A * aptr)

{ aptr->Test(); }

void main()

{

D dobj(2,3,4);

temp(&dobj); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!