473,323 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Subject: Use of new and delete in C++

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
Jul 23 '05 #1
4 1554
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. Is there a way to make the destructor aware of the
array, or to make it public to the class from within the constructor?
Make your array (pointer) a member. Initialise it in the constructor,
delete it in the destructor. It seems so straightforward that I am
thinking there is a catch in your explanation, which I've missed.

What book are you reading to understand dynamic memory better?
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.


It doesn't really seem relevant where the dynamic memory is used or
what it represents.

V
Jul 23 '05 #2

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:co********************@comcast.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. Is there a way to make the destructor aware of the
array, or to make it public to the class from within the constructor?
Make your array (pointer) a member. Initialise it in the constructor,
delete it in the destructor. It seems so straightforward that I am
thinking there is a catch in your explanation, which I've missed.

You're right... it was straightforward... I'm just trying to learn so much
at one time, that I guess I overlooked that. Thanks for the tip. What book are you reading to understand dynamic memory better? "C++ From the Ground Up", by Herbert Schildt... is he any good? I have two
C++ books by him. If he isn't good, can you recommend a really good book /
author?
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.


It doesn't really seem relevant where the dynamic memory is used or
what it represents.

V

Jul 23 '05 #3
Eric A. Johnson wrote:
You're right... it was straightforward... I'm just trying to learn so much
at one time, that I guess I overlooked that. Thanks for the tip.
What book are you reading to understand dynamic memory better? "C++ From the Ground Up", by Herbert Schildt... is he any good? I have

two C++ books by him. If he isn't good, can you recommend a really good book / author?


Please hit:

http://groups-beta.google.com/groups...p.lang.c%2B%2B

This group tends to dislike Schildt. He's a very good writer for warm
friendly prose, and very bad for technical details or thoroughness.

Go ahead and learn from the book, but make sure you read many more. These
can't hurt:

Accelerated C++
The C++ Programming Language, 3rd Edition

Others will recommend more.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 23 '05 #4

"Eric A. Johnson" <no*****@dontlookforme.com> skrev i en meddelelse
news:4o******************@newssvr14.news.prodigy.c om...
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.
You should use a std::vector (or perhaps a std::string) for this purpose.
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.
As Victor Bazarov suggested, it is possible, but beware that you also must
create a correct copy-constructor now. It is much easier just to use the
std:: containers mentioned above.

Peter
[snip]
Thanks in Advance,
Eric

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave | last post by:
Hello all, In the code below, I see the following output: base::operator new(size_t, int) base::base() base::~base() base::operator delete(void *) In the case of an exception being thrown...
48
by: David J Patrick | last post by:
I'm trying to rewrite the CSS used in http://s92415866.onlinehome.us/files/ScreenplayCSSv2.html. using the w3.org paged media standards as described at http://www.w3.org/TR/REC-CSS2/page.html ...
1
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. In fact there...
3
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. I am...
2
by: Dave | last post by:
Hello all, I'd like to find a source on the web that discusses, in a comprehensive manner and in one place, everything about new / delete. It should include overloading operator new, the new...
0
by: PaulB | last post by:
Microsoft Access Performance FAQ (Last updated 2006/01/23) Try the following suggestions as originally suggested by Frank Miller of Microsoft PSS and extensively updated by me. Almost all of...
9
by: rohits123 | last post by:
I have an overload delete operator as below ////////////////////////////////// void operator delete(void* mem,int head_type) { mmHead local_Head = CPRMemory::GetMemoryHead(head_type);...
10
by: jeffjohnson_alpha | last post by:
We all know that a new-expression, foo* a = new foo() ; allocates memory for a single foo then calls foo::foo(). And we know that void* p = ::operator new(sizeof(foo)) ; allocates a...
4
by: Alec MacLean | last post by:
Is anyone aware of a size limit imposed on the subject text when using the System.Net.Mail library? I'm getting problems of message not being recieved if the subject exceeds 15 chars. Thx
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.