C++ question.

Started by
3 comments, last by mrmrcoleman 20 years ago
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
Advertisement
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
Syntactically everything looks ok.

Stating the obvious, make sure newOutputArea is not 0.

Step through the code as see where it bombs.
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.
Its ok, I worked it out.

Cheers guys.

This topic is closed to new replies.

Advertisement