Subject: Use of new and delete in C++

  • Follow


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 


0
Reply nothere4 (32) 3/25/2005 11:46:27 PM

Eric A. Johnson wrote:

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

Post some code to news:comp.lang.c++

And I suspect this is a non-problem. Store a pointer to the CHAR_INFO, and
delete it in the destructor. What am I missing?

> On a side note, has anybody else written advanced console applications?

Google ncurses, and you'l find a Win32 version. Except I think CMD.EXE obeys
ANSI escape codes, so everything might happen as strings of commands to the
window, not raw memory-mapped activities. Fun though they are...

-- 
  Phlip
  http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces


0
Reply phlip_cpp (3649) 3/25/2005 11:56:53 PM


"Phlip" <phlip_cpp@yahoo.com> wrote in message 
news:9z11e.11109$ZB6.4200@newssvr19.news.prodigy.com...
> Eric A. Johnson wrote:
>
>>     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.
>
> Post some code to news:comp.lang.c++
Did it!
>
> And I suspect this is a non-problem. Store a pointer to the CHAR_INFO, and
> delete it in the destructor. What am I missing?
I'm somewhat of a beginner.  When you tell me to "Store a pointer to the 
CHAR_INFO", are you telling me to declare it in the class declaration?  I 
just tried that, and it seems to work so far... I reckon I ought to have 
thought of that.  Thank you!
>> On a side note, has anybody else written advanced console applications?
>
> Google ncurses, and you'l find a Win32 version. Except I think CMD.EXE 
> obeys
> ANSI escape codes, so everything might happen as strings of commands to 
> the
> window, not raw memory-mapped activities. Fun though they are...
I'll check out ncurses, thanks for the tip.
>
> -- 
>  Phlip
>  http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
>
> 


0
Reply nothere4 (32) 3/26/2005 12:24:27 AM

2 Replies
41 Views

(page loaded in 0.172 seconds)

12/8/2012 10:09:36 PM


Reply: