Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > BOOK: Beginning Visual C++ 6
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning Visual C++ 6
This is the forum to discuss the Wrox book Beginning Visual C++ 6 by Ivor Horton; ISBN: 9780764543883
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C++ 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 5th, 2012, 12:25 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.

Last edited by RichS727; September 5th, 2012 at 05:28 PM.. Reason: Code download has the same error as in the book


Similar Threads
Thread Thread Starter Forum Replies Last Post
Having problem in operator overloading nimvc BOOK: Professional C++ 1 March 29th, 2010 08:33 PM
Overloading dotnetDeveloper ASP.NET 3.5 Basics 1 March 4th, 2009 03:19 PM
Overloading nayeem69 .NET Framework 2.0 1 July 17th, 2007 12:30 AM
Overloading Overriding arv1980 VS.NET 2002/2003 2 January 22nd, 2006 12:55 AM
Overloading Initialize_Class sg48 Excel VBA 1 July 11th, 2003 07:47 AM





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