Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > Visual C++
| Search | Today's Posts | Mark Forums Read
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ 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 August 21st, 2003, 10:02 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default I.H. Beginning VC++ 6 (p.649):SetSize()

Hi,

The book says:

To set the initial size of a CArray, you call the SetSize() function. That in turns calls ConstructElements(), which allocates memory for the number of elements, but does not call a constructor for your object class. You need to supply your own version of ConstructElements() if your objects contain dynamically allocated data members.

1)How does ConstructElements() allocate memory without calling the object's constructor? Does it use sizeof(class_name)?

2)Why can you store an object, but if you want to store an object with a dynamically allocated data member, you have to do something extra ?

3)How would a version of ConstructElements be implemented for a simple object like this(assuming CArray is declared: CArray<A, A&> aArray):
Code:
class A
{
public:
     A(int* p)
     {
          pint = new int;
          *pint = *p; 
     }

private:
     int* pint;
};


Similar Threads
Thread Thread Starter Forum Replies Last Post
VC++ 6 dannytran Visual C++ 0 January 4th, 2006 07:49 AM
Help us in VC++ MMazhar Visual C++ 0 December 10th, 2005 03:49 PM
convert VC++ 5.0 project to VC++ 6.0 MIDL ERR mdahd90943 Visual C++ 0 May 26th, 2005 08:57 AM
Has anyone tried Beginning VC#? CSharpUser BOOK: Beginning Java 2 2 December 28th, 2004 06:00 PM
Chapter 15, page 648-649 (Beginning ASP 3.0) JB977 Wrox Book Feedback 0 February 16th, 2004 05:27 PM





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