p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning Visual C++ 6 (http://p2p.wrox.com/forumdisplay.php?f=36)
-   -   Example EX8_10 Constructor Overloading (http://p2p.wrox.com/showthread.php?t=88387)

RichS727 September 5th, 2012 12:25 PM

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
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.

All times are GMT -4. The time now is 11:56 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.