Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Family basic steps to socialization write a short note ?

Answered: 1 week ago

Question

What does physics deal with?

Answered: 1 week ago