I am trying to uderstand how default constructors work. Can someone please show me how they would be included in the following example not a perfect code I know, just trying to determine where it would fit in. Thanks
std::string myName; // Runs the default constructor (ie, the constructor that takes no parameters)
In this case, the default constructor sets the string to an empty string (what else would it do?)
Example default constructor:
1 2 3 4 5 6 7 8
class Foo {
int bar;
int baz;
public:
Foo() // default constructor - takes no parameters
: bar(), baz() // this is better than bar = 0; baz = 0;
{} // body of constructor is empty
};