0
Sir / Mam please tell me why this c++ program calling the base class variable when its private ??
#include<iostream> using namespace std; class base { private : int basevar; public: base() { cout<<"enter the value of base variable "; cin>>basevar; } void display() { cout<<"base variable value is "<<basevar<<endl; } }; class derived : public base { private: int dervar; public: derived() { cout<<"enter the value of derived variable "; cin>>dervar; } void display() { base:: display(); cout<<"derived variable value is "<<dervar<<endl; } }; int main() { derived a,b; a.display(); b.display(); return 0; }
2 Respuestas
+ 4
In the same class private variables or members function are accessible inside base class u have declared one variable basevar and constructor and another Function display when u will create object constructor will call and here u taking input and display Function will print this basevar . Try to access this variable in main or derived class it will give u error
0
Ooh thanks bro