Problem - Class member data being overwritten

Started by
2 comments, last by Rottbott 22 years, 10 months ago
Hi, I have a problem with one of my classes. For convinience, all class member data is PUBLIC at the moment, which may effect it, but I still can''t see why this is happening. I have a certain class which just holds a few ints and floats and stuff. I have another, similar class. To access them I have declared an array of pointers (the pointers for each class are kept in seperate arrays), and I am creating pointers to objects of each class when I create the objects: PointerArray[ObjectNumber] = new Object; I have a line in my code which, like other similar lines around it, sets up some class member data: PointerArray[Object]->MemberData = SomeInteger; However, it appears to be overwriting member data of another class as well! For instance: PointerArrayForClass1[Object]->MemberData = SomeInteger; Not only is this setting Class1.MemberData to SomeInteger, it is (somehow) also setting Class2.OtherMemberData to SomeInteger. I have NO idea why this happens, can anyone shed some light? Thanks Rottbott
Advertisement
Do you have some code samples to show?

Do you declare your lists as static lists? Are you initialize the second list with a pointer from the first list?

I am declaring them as static, although outside any functions so that could be it...

As for showing code, I''d love to, but it''s part of a large project and is scattered everywhere.

So shall I try sticking the declarations in an Init() function?


Rottbott
Hah - wait, I just realised I can''t declare the pointer arrays inside a function, because I need them to be available in any function.


Rottbott

This topic is closed to new replies.

Advertisement