What won't these codes run? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What won't these codes run?

I'm trying to find out the reason why these two chunks of code won't run. Problem 1 ======== class A { }; class B : public A{ public: int x; B() { x=10; } }; int main(){ A*p; B d; p=&d; cout<<p->x; // Why isn't the output 10? } // Is it because x MUST be in class A? Problem 2 ======== class A { }; class B:public A{ }; int main(){ A ob1; B ob2; ob2=ob1; // Will this not run because of 1) a lack of constructors or } 2) it's forbidden to assign to objects?

4th Aug 2020, 1:15 AM
Solus
Solus - avatar
0 Answers