Wrox Programmer Forums
|
BOOK: Ivor Horton's Beginning Visual C++ 2005
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2005 by Ivor Horton; ISBN: 9780764571978
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2005 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
 
Old July 5th, 2006, 10:36 AM
Authorized User
 
Join Date: May 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ex9_03, page 483 & '571974 Code from the book'

Odd problem here: I had an error so I compared with the relevant files in the source code (i.e. '571974 Code from the book').

Problem exists around CandBox.h
In the book, page 483, we have:
---
...
cout << endl <<"CCandyBox constructor2 called";
m_Contents = new char [strlen(str) + 1];
strcpy_s(m_Contents, strlen(str)+1, str);
}

//constructor to set contents
//calls default CBox constructor automatically
CCandyBox(char* str ="Candy")
{
cout<< endl<< "CCandyBox constructor1 called";
m_Contents = new char [strlen(str)+1];
strcpy_s(m_Contents, strlen(str)+1, str);
...

-------------------

In the source code ('571974 Code from the book'), two lines are changed:
Both entries of: strcpy_s(m_Contents, strlen(str)+1, str);
have been changed to:
strcpy_s(m_Contents, strlen(m_Contents), str);

strlen(m_Contents)... causes the executable to crash, although I have not worked out why. m_Contents and str are the same.

The crash seems to occur when it comes to displaying '<< sizeof myBox' in EX9_03.cpp





 
Old July 6th, 2006, 02:21 AM
Authorized User
 
Join Date: May 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have found the solution, which is to replace
strcpy_s(m_Contents, strlen(m_Contents), str);

with

strcpy_s(m_Contents, strlen(m_Contents)+1, m_Contents);



 
Old September 23rd, 2006, 01:29 PM
Authorized User
 
Join Date: Oct 2005
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes. I've had this problem too, but didn't know why. I've done what you said and it now works. Thanks for pointing this out.

Dan Crossley





Similar Threads
Thread Thread Starter Forum Replies Last Post
EX9_03.CPP "bug" found/explained Matthew Doucette BOOK: Beginning Visual C++ 6 0 April 8th, 2005 10:48 AM
Linux & KDE & C++ & QT & MYSQL & Kdevelop Munnnki Linux 0 January 2nd, 2005 05:41 PM
book for c# & .net yescarthik C++ Programming 0 November 30th, 2003 07:01 AM
book examples not on code download page jb4mt JSP Basics 3 September 23rd, 2003 01:18 AM





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