Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2008 by Ivor Horton; ISBN: 9780470225905
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 25th, 2012, 11:51 AM
Registered User
Points: 18, Level: 1
Points: 18, Level: 1 Points: 18, Level: 1 Points: 18, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2012
Location: USA
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Chapter 9, Class Members as Friends (broken code)

The short version: the example code is broken and the errata for the book doesn't list this. The 2010 edition of the book goes into much more detail, but even that code is still broken.

The fix seems to be either:

Code:
#include carton.h
inside of bottle.h or

Code:
friend class CCarton
inside of the CBottle class.

This looks like:

Code:
#pragma once

#include "carton.h"

class CBottle
{
public:
    CBottle(double height, double diameter);

private:
    double m_Height; // Bottle height
    double m_Diameter; // Bottle diameter

// Let the carton constructor in
friend CCarton::CCarton(const CBottle& aBottle);
};
or

Code:
#pragma once

class CBottle
{

friend class CCarton;

public:
    CBottle(double height, double diameter);

private:
    double m_Height; // Bottle height
    double m_Diameter; // Bottle diameter

};
respectively.

More info available on the cboard forums here.

P.S.

Both page 530 (2008 edition) and page 571 (2010 edition) have the syntax for adding a friend declaration within the CBottle class definition wrong:

Code:
friend CCarton;
when it should be (at least according to other resources):

Code:
friend class CCarton
Hope that helps someone.

Last edited by deoren; February 25th, 2012 at 12:04 PM.. Reason: Fixed code formatting
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Interesting Ideas, Broken Download code Hamish BOOK: ASP.NET 3.5 Website Programming Problem Design Solution 8 December 10th, 2009 07:28 AM
using members of a C Sharp class Bill_Thompson C# 2005 4 January 13th, 2009 06:04 PM
ZIP with code is broken! CROmagnon BOOK Beginning CSS: Cascading Style Sheets for Web Design, 2nd Ed; ISBN: 978-0-470-09697-0 2 May 23rd, 2008 11:28 AM
hai friends, Regarding Client-side code. sridharmohan15 ASP.NET 1.0 and 1.1 Professional 2 November 27th, 2006 08:19 AM



All times are GMT -4. The time now is 01:48 AM.


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