Which signature correctly declares a copy constructor for class Widget in C++?
Correct answer
D. Widget(const Widget& other);
14 views
D. Widget(const Widget& other);
14 views
A copy constructor builds a new object from an existing one and takes a reference, conventionally const, as in Widget(const Widget&). It must take a reference because by-value would require another copy, a circular requirement the language forbids. The signature with operator= is copy assignment, which runs on an already-constructed object and must release existing resources first.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is D? Ask here and get an explanation.