List of all available Websheets
Viewing cpp/cs104/classes/ctor-init-list-shadow 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 | Figure out why <tt>m1</tt> and <tt>m2</tt> do not have the expected values of <tt>3.8</tt> and <tt>3.95</tt>, respectively. </ol> <p><strong>Learning goal:</strong> </p> <ul><li>Beware of <strong>declaring variables that shadow a member</strong></li> <li>Use the constructor initialization list to initialize members</li> </ul> |
Remarks Comments, history, license, etc. | Copied from problem cpp/cs104/classes/ctor-initialization-list (author: redekopp@usc.edu) Copied from problem cpp/cs104/classes/ctor-dtor-members (author: redekopp@usc.edu) 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() { x = 1.0; cout << "Default A1 ctor - x = " << x << endl; } A1(double myx) { x = myx; cout << "Init A1 ctor - x = " << x << endl; } ~A1() { cout << "A1 dtor - x = " << x << endl; } double x; ]\ }; class A2 { public: \[ REDACTED \show: A2() { A1 m1(3.8); A1 m2(3.95); 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 | |
Add compiler flag(s) json list of flags e.g. ["-Wno-unused-variable"] | ["-w"] |
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'.