| shahbazsaleem (14) | |
|
In the below code i can't understand highlighted code... #include<iostream> #include<conio.h> #include<Windows.h> using namespace std; class A { protected: int data; public: void show() { data=2;//cout<<data; } }; class B : public A { public: B(const A &a): A(a) //explain this line please { cout<<data; } }; int main() { A a; a.show(); B b = a; getch(); return 0; } | |
|
|
|
| Zhuge (2880) | |
| That's using an initializer list to use a particular constructor of A when initializing the A portion of a B. | |
|
|
|
| shahbazsaleem (14) | |
| if i want to change the value of data of object a through object B how it is possible??? | |
|
|
|
| Zhuge (2880) | |
| You mean change the value of a member B inherits from A? You can just access it like a normal member (assuming access is allowed). | |
|
|
|