What code fragments contain errors (compilation, execution, logical)?
Explanation
(1) - error, because reference a can be initialized only in the initialization list.
(2) - an error because the reference a refers to the local variable b passed to the constructor as an argument. When exiting the constructor, the b variable will be destroyed and the value a becomes undefined.
(3) - no error. Here the reference a is equivalent to *this.
(4) - error. A is incomplete type while defining A a;

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes