Wrox Programmer Forums
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 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 March 26th, 2010, 02:25 PM
Authorized User
Join Date: Feb 2010
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Question chapter 9 exercise problem 1

Regarding Chapter 9 exercise problem 1:
The question is “What’s wrong with the following code?” …, and is not “how should the class be rewritten to improve it?”.

The online SOLUTION offers:
// Soln 9_1

CBadClass initializes the member p in the contructor with the address passed as the argument.
The argument to the constructor could be a string allocated on the heap that could be
destroyed externally. This would leave the object with an invalid pointer.
The constructor should copy the argument and there should be a destructor to release the memory for p.
It is also possible the argument to the constructor could be null.
The default constructor does not initialize the members at all.
The class would be better defined as below.

#include <cstring>

class CBadClass
int len;
char* p;
CBadClass(const char* str=0):len(0)
len = strlen(str);
p = new char[len+1];
strcpy_s(p, len+1, str);

When I started to think about how to answer the exercise question, before I looked at the on-line solution, my thought was along the lines of the above, with the main thing being that the string is not copied into an array that is inside the class.

After thinking more about it, my conclusion was, and is, that the main thing wrong with original class is that there is no way to access p in any code that incorporates the class, because p is private, and the original class provides no other means of indirectly accessing p. Given that, the on-line solution is at best incomplete.

Do you agree? Did I miss something?
Old December 20th, 2011, 10:31 PM
Registered User
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ivor Horton's Visual C++ 2008 ,(p620) ,Ex10_2

1. Even I corrected the Ex10_02 as the Errata showed, I still failed
2. Could anyone tell me how to do this exercise from the begining?
3. I used:
a. file>new project
b. CLR empty project
c. (right click of source files ) Add existing item from the code of CH10_02.
d. (right click of header files) Add existing item (person.h) from the
code of CH10_02
e. run the Ex10_02.cpp
f. fail.
Old December 21st, 2011, 05:38 AM
Registered User
Join Date: Dec 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cannot put value in a textarea ,on blackberry

I have an asp.net application(MVC) that run on blackberry.In this I have a grid and when user click on a row of the grid i get value from a column that is hidden and i want to show in a textarea.

This is the control that i should click:
       <td   colspan="3"> 
    <a id="ModelS<% = Model.Id  %>" href="#"  onclick ="javascript:ShowBody('B<% = Model.Id  %>')">
This is the code for control that i shoult read :
     <td  id="B<%=Model.Id%>" style="display: none; " > 
         <%= Model.Body%>
When I click i run function :
         function ShowBody(stringId) {
             var obj1
             var obj2

             obj1 = document.getElementById(stringId);
             obj2 = document.getElementById("BodyMessDetailed");

             obj2.value = obj1.innerText;
and here must arrive the information:
      <textarea id="BodyMessDetailed"  readonly="readonly" cols="1" rows="10" name="TT"
                      style="width:98%;height:90%; overflow:scroll;" 
I checked and if i put a string instead obj1.innertext goes ok .But If I let obj1.innertext ,doesn't put anything.I try with value, textcontent but also doesn't work.

Can somebody help me ?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 5 Exercise 2 diango BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 4 February 1st, 2011 03:24 PM
problem in the exercise chapter 6 derrida BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 March 16th, 2007 08:48 AM
Chapter 2 Last Exercise has some problem james_027 BOOK: Beginning JavaServer Pages 1 May 25th, 2005 08:19 PM
Problem with Chapter 2, Exercise 2 paultf BOOK: Beginning Java 2 3 December 1st, 2003 06:13 AM
Problem with exercise in chapter 19 backslash BOOK: Beginning Visual C++ 6 4 September 5th, 2003 11:46 AM

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