Example EX8_10 Constructor Overloading
I am using Microsoft Visual C++ 2010 Express
I am getting error
1>------ Build started: Project: EX8_10, Configuration: Debug Win32 ------
1>EX8_10.cpp(36): warning C4520: 'CBox' : multiple default constructors specified
1>EX8_10.cpp(54): error C2668: 'CBox::CBox' : ambiguous call to overloaded function
1> EX8_10.cpp(19): could be 'CBox::CBox(void)'
1> EX8_10.cpp(12): or 'CBox::CBox(double,double,double)'
1> while trying to match the argument list '(void)'
1> This diagnostic occurred in the compiler generated function 'void CBox::__dflt_ctor_closure(void)'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
What is generated function 'void CBox::__dflt_ctor_closure(void)'
and why is it having a problem with the overloaded constructor?
The rest of the program is not having a problem with the constructors.
Forget it - I shoud have checked Errata first.
Also the available download of example code for the book does not have the error corrected as specified in errata:
310 Page 310: Arrays of Class Objects
The constructor definition in Exercise 8_10 should read:
CBox(double lv, double bv = 1.0, double hv = 1.0): m_Length(lv), m_Breadth(bv), m_Height(hv)
cout << endl << "Constructor called.";
The code shown in the book causes ambiguity over which constructor should be called, giving rise to the compiler errors described on page 295. In the code in the book, both constructors could be used to initialize the data members of the CBox objects in the array boxes. If a default value for lv is not supplied in the first constructor, the compiler knows it cannot use that constructor for the initialization and so uses the default constructor.
Last edited by RichS727; September 5th, 2012 at 05:28 PM..
Reason: Code download has the same error as in the book