List of all available Websheets
Viewing cpp/cs104/classes/ctor-dtor-members by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | Consider the class/struct <tt>A2</tt> below that uses the <tt>A1</tt> object from a previous exercise. </ol> <p><strong>Learning goal:</strong> </p> <ul><li>When one object is composed of others, what ordering of constructor calls are made?</li> <li>What is the ordering of destructor calls?</li> </ul> |
Remarks Comments, history, license, etc. | Copied from problem cpp/cs104/classes/ctor-default (author: redekopp@usc.edu) Copied from problem cpp/cs104/classes/constructor_init (author: redekopp@usc.edu) |
Engine | |
Template / Reference solution |
using namespace std; struct A1 { \[ REDACTED \show: A1() { cout << "Default A1 ctor" << endl; x = 1.0; } A1(double myx) { cout << "Init A1 ctor" << endl; x = myx; } ~A1() { cout << "A1 dtor" << endl; } double x; ]\ }; class A2 { public: \[ REDACTED \show: A2() { cout << "Default A2 ctor" << endl;} ~A2() { cout << "A2 dtor" << endl; } ]\ void print() const { cout << "m1=" << m1.x << " m2=" << m2.x << endl;} private: A1 m1; A1 m2; }; int main() { \[ REDACTED \show: A2 obj1; obj1.print(); ]\ return 0; } |
C++ test suite json list of stdin/args tests e.g. [{"stdin":"hi", "args":["4", "5"]}, {"stdin":"noargs"}] to just run once with no input use [{}] | [{}] |
Is example? i.e., just a demo |
Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.