Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| 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 March 26th, 2010, 02:25 PM
Authorized User
 
Join Date: Feb 2010
Location: MA
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
{
private:
int len;
char* p;
public:
CBadClass(const char* str=0):len(0)
{
if(p)
{
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?
  #2 (permalink)  
Old December 20th, 2011, 10:31 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
  #3 (permalink)  
Old December 21st, 2011, 05:38 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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:
Code:
       <td   colspan="3"> 
    <a id="ModelS<% = Model.Id  %>" href="#"  onclick ="javascript:ShowBody('B<% = Model.Id  %>')">
        <%=Model.Subject%>
        </a></td>
This is the code for control that i shoult read :
Code:
     <td  id="B<%=Model.Id%>" style="display: none; " > 
         <%= Model.Body%>
    </td>
When I click i run function :
Code:
         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:
Code:
      <textarea id="BodyMessDetailed"  readonly="readonly" cols="1" rows="10" name="TT"
                      style="width:98%;height:90%; overflow:scroll;" 
                      >
      </textarea>
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 ?
 


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



All times are GMT -4. The time now is 10:46 PM.


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