9. In the following code, indicate if the selected lines are legal or illegal: #
ID: 3878865 • Letter: 9
Question
9. In the following code, indicate if the selected lines are legal or illegal: #include class small public: small( ) {size = 0;}; void k() const; void h(int i) friend void f (small z); private: int size; void small::k ) const small x, y; x=y; // LEGAL/ ILLEGAL? x.size =y.size; // LEGAL/ILLEGAL ? x.size -3; /7 LEGAL/ILLEGAL? void small::h(int i) void f (small z) small x, y; x =y; // LEGAL / ILLEGAL ? x.size -y.size; // LEGAL/ILLEGAL? x.size 3; /7 LEGAL/ILLEGAL? x.h(42); // LEGAL/ILLEGAL? int main) ( small x, y; x=y; // LEGAL/ ILLEGAL? x.size =y.size; // LEGAL/ILLEGAL ? x.size -3; /7 LEGAL/ILLEGAL? x.h(42); // LEGAL/ILLEGAL? std: :coutExplanation / Answer
x=y is LEGAL
x.size = y.size is ILLEGAL because size is private and cannot be accessed through reference
x.size = 3; is also IILEGAL for the above said reason.
x.h(42) is LEGAL as function h is declared public.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.