List of all available Websheets
Viewing cpp/cs104/classes/ctor-default 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>A1</tt> below. <p>Try the various combinations of constructing an object using the <strong>default</strong> constructor and an <string>initializing</string> constructor. </p> <ol><li>With initializing ctor only (don't define any ctor in <tt>A1</tt>)</li> <li>With default constructor only (don't define any ctor in <tt>A1</tt>)</li> <li>Then define an initializing ctor and try to get <tt>obj2</tt> definition to compile </li> <li>Then define both a default and an initializing ctor and try to get both objects to compile </li> </ol> <p><strong>Learning goal:</strong> </p> <ul><li>When does the compiler generate a default constructor and when does it not?</li> <li>What does the default constructor do?</li> </ul> |
Remarks Comments, history, license, etc. | Copied from problem cpp/cs104/classes/constructor_init (author: redekopp@usc.edu) |
Engine | |
Template / Reference solution |
using namespace std; struct A1 { \[ REDACTED \show: double x; ]\ }; int main() { \[ REDACTED \show: // A1 obj1; // cout << "obj1's value of x: " << obj1.x << endl; A1 obj2(3.9); cout << "obj2's value of x: " << obj2.x << endl; ]\ 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'.