Archived

This topic is now archived and is closed to further replies.

mrmrcoleman

C++ question.

Recommended Posts

mrmrcoleman    320
I have a class (Screen) with an internal member of type OutputArea* which is called ScreenOutputArea. To set this internal member I have a method which looks something like this.
void Screen::SetOutputArea(OutputArea* newOutputArea)
{
   ScreenOutputArea = new OutputArea(*newOutputArea);
}
ScreenOutputArea is type OutputArea*. And the OutputArea class has its copy constructor defined to accept a reference to OutputArea. At first I thought this was ok, but now I am getting a run-time crash somwhere around this class and I think this may be the problem. Can anybody see any probs with this? Thanks in advance. Mark Coleman

Share this post


Link to post
Share on other sites
Colin Jeanne    1114
That code looks fine except that it could result in a memory leak if ScreenOutputArea is not deleted prior to this call.

Instead of "somewhere around this class" use your debugger to find out exactly where the crash is occuring.


Thanks Salsa!Colin Jeanne | Invader''s Realm
"I forgot I had the Scroll Lock key until a few weeks ago when some asshole program used it. It even used it right" - Conner McCloud

Share this post


Link to post
Share on other sites
ABC123    122
Syntactically everything looks ok.

Stating the obvious, make sure newOutputArea is not 0.

Step through the code as see where it bombs.

Share this post


Link to post
Share on other sites
mrmrcoleman    320
Sorry guys I havent done much debugging in the past (well in fact I havent done any other than the usual MessageBox experiments) so do you think you might be able to help me out?

I am stepping through the program and when I get to a ZeroMemory function call, the compiler asks me to provide MEMSET.ASM?

However I cant locate this file anywhere on my computer?

Any ideas?

Thanks.

Share this post


Link to post
Share on other sites