Help needed on constructors!

This is a discussion on Help needed on constructors! within the C++ Programming forums, part of the General Programming Boards category; Modify the default constructor to that the data member is initialized to zero in the initialization list. Provide a second ...

Help needed on constructors!

Modify the default constructor to that the data member is initialized to zero in the initialization list. Provide a second constructor to allow "Integer" objects to be created and initialized with a value.
In your test program, write a function that takes an Integer object as an argument, first by value and then by reference. What do you see printed from constructors and destructors when the function is called? Explain what you understand in a few statements.

Oh, I notice that your code also has another default constructor declared. That would be an error. If you want to declare a constructor with no parameters, then your constructor that has three parameters should not have default arguments for all the parameters, otherwise it would also be a default constructor. A class can only have one default constructor.

You are saying that if the argument that corresponds to the parameter h is not supplied when this constructor is invoked, then h will default to having a value of 3. Likewise, if the arguments corresponding to both h and w are both not supplied, then w will have default to having a value of 2. If no arguments are supplied, then l will default to having a value of 1.

Problem is, you also declared:

Code:

R();

defining it as:

Code:

R::R():danish1(0){
cout<<"\nR Default constructor is called\n";
}

So, if you create an object of R without supplying any arguments to its constructor, which constructor should be called? That is an ambiguity there.

You are saying that if the argument that corresponds to the parameter h is not supplied when this constructor is invoked, then h will default to having a value of 3. Likewise, if the arguments corresponding to both h and w are both not supplied, then w will have default to having a value of 2. If no arguments are supplied, then l will default to having a value of 1.

Problem is, you also declared:

Code:

R();

defining it as:

Code:

R::R():danish1(0){
cout<<"\nR Default constructor is called\n";
}

So, if you create an object of R without supplying any arguments to its constructor, which constructor should be called? That is an ambiguity there.