For Programmers: Free Programming Magazines  


Home > Archive > Visual Studio > March 2005 > Subject: Use of new and delete in C++









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Subject: Use of new and delete in C++
Eric A. Johnson

2005-03-25, 8:57 pm

Hi,

I am working on a way to create a "window" within a dos console. I'm
using Microsoft Visual C++. My main problem is that I am using new to
create a new CHAR_INFO array within the constructor, and I want to destroy
it within the destructor using delete. However, the array is not known
outside of the constructor. This is a class within a class. Until the
object is created, it has no way to know the size of the array; the size is
passed as a parameter to the constructor. Is there a way to make the
destructor aware of the array, or to make it public to the class from within
the constructor? I am using it to store the original information of the
screen that will be overwritten, so that when the window is finished, it can
rewrite the original information (including the background and foreground
color) before the "window" is completely destroyed.

On a side note, has anybody else written advanced console applications? How
did you handle "windows"? If I can get this to work properly, I plan to,
eventually, use it to create menus and so on within the console.

Thanks in Advance,
Eric


BobF

2005-03-26, 3:58 am

declare a pointer at the level of scope you need, and create the storage it
points to in the constructor with 'new'. use "delete [] pointer;" in the
destructor.

"Eric A. Johnson" <nothere@dontlookforme.com> wrote in message
news:7q11e.15490$C47.11253@newssvr14.news.prodigy.com...
> Hi,
>
> I am working on a way to create a "window" within a dos console. I'm
> using Microsoft Visual C++. My main problem is that I am using new to
> create a new CHAR_INFO array within the constructor, and I want to destroy
> it within the destructor using delete. However, the array is not known
> outside of the constructor. This is a class within a class. Until the
> object is created, it has no way to know the size of the array; the size

is
> passed as a parameter to the constructor. Is there a way to make the
> destructor aware of the array, or to make it public to the class from

within
> the constructor? I am using it to store the original information of the
> screen that will be overwritten, so that when the window is finished, it

can
> rewrite the original information (including the background and foreground
> color) before the "window" is completely destroyed.
>
> On a side note, has anybody else written advanced console applications?

How
> did you handle "windows"? If I can get this to work properly, I plan to,
> eventually, use it to create menus and so on within the console.
>
> Thanks in Advance,
> Eric
>
>



Eric A. Johnson

2005-03-26, 3:59 am


"BobF" <rNfOrSePeAzMe@charter.net> wrote in message
news:%23EfyTLaMFHA.1392@TK2MSFTNGP10.phx.gbl...
> declare a pointer at the level of scope you need, and create the storage
> it
> points to in the constructor with 'new'. use "delete [] pointer;" in the
> destructor.

Did it... thanks! :-)
>
> "Eric A. Johnson" <nothere@dontlookforme.com> wrote in message
> news:7q11e.15490$C47.11253@newssvr14.news.prodigy.com...
> is
> within
> can
> How
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com