Multiple object share problem

This is the skeleton of my app.
1
2
3
4
5
- ClassA       has a    ClassE    * myclassE_inside_A    public var.
    - ClassB    Inherits ClassD 
    - ClassC    Inherits ClassD  

- ClassD has some funtions and  *ClassE public var. 


The idea was to deal with classE instance from class A, B and C. And use some common methods of ClassD from ClassB and ClassC.

Pseudocode that describes its operation.
1
2
3
4
5
6
7
8
9
10
11
12
Inside ClassA:
    ClassB my_classB;    
    my_classB.create;   (I have the *ClassE filled with data )
    myclassE_inside_A = my_classB.classE;

    ClassC my_classC;
    ClassC.set_classE(my_classE_insideA); 
    for(   ) 
    {  do some things with my_classE_inside_A ;
        classC.modify_some_things_on_classE }    

    -  classC.modify_some_things_on_classE uses own methods and one function  inheritated from classD. 


When I run the program I have a lot a heap error and a lot of crahes
HEAP: Free Heap block c977e28 modified at c977e5c after it was freed
(Internal error: pc 0x2ff in read in psymtab, but not in symtab.)
(Internal error: pc 0x2ff in read in psymtab, but not in symtab.)
(Internal error: pc 0x2ff in read in psymtab, but not in symtab.)
,,,,

The error was related with classC, after the first modification of classE object. the second time I use it (it is the same if I do it from myclassE_insideA or int classC) i have the crash.
I'm sure that I' forget to do something but I dont view it.

It is as If I can't use the classE object by pointer. ?

Any idea ?
Last edited on
HEAP: Free Heap block c977e28 modified at c977e5c after it was freed
I'd say that's quite clear, isn't it? You delete memory and use it later. To circumvent those problems I recommend using smart pointer.
Yes, but I have not memory delete operations. I think that some 'temporal' elements are deleting itself without control ?

But, Why is the reason becasue If I dont make any modifications so classE throughout classC I have not crash ? I'm sure the problem was here, I have spent all the morning without success....


Inside classD, I have only declare that I have a public pointer of a classE.
Have I to create an empty instance of class E and then set it to the pointer received???



Thanks.
Last edited on
I think that some 'temporal' elements are deleting itself without control ?
Yes they do. If you access a pointer to such an object that is gone could cause those problems as well.

Or

It could be an uninitialized pointer.
Topic archived. No new replies allowed.