# include<stdio.h> # include<iostream> # include<conio.h> using namespace std; class Base{ public: Base(int i, float f, double d): i(i), f(f), d(d) { } virtual void Show()=0; protected: int i; float f; double d; }; class Derived: public Base{ public: Derived(int i, float f, double d): Base( i, f, d) { } void Show() { cout<< "int i = "<<i<<endl<<"float f = "<<f<<endl <<"double d = "<<d<<endl; } }; int main(){ Base * b = new Derived(10, 1.2, 3.89); b->Show(); return 0; }
This is a working example if you want to initialize the base class data elements present in an object of the Derived class, while you want these values to interact by calling the constructor of the Derived class.
manish srivastava Sep 07 '17 at 9:40 2017-09-07 09:40
source share