Click here to Skip to main content
15,914,221 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We are creating two similar class objects.

Ex:

C++
Class A; // the class is having some pointer member variables.

A obj;
A obj1;


Obj: is constructed properly and member variables are pointing to valid addresses and values.
Obj1: during construction stage the member variables pointing to valid addresses and values once complete the construction the member variables are pointing to zunk values.


Please help me how to proceed further on this issue. I have no prior knowledge on memory corruption.
Posted
Updated 22-Nov-11 0:55am
v2
Comments
Timberbird 22-Nov-11 6:10am    
It is impossible to answer this question until you provide more info on class A - at least its fields and default constructor (and, possibly, base classes' constructors as well)
dharmakiran 22-Nov-11 8:47am    
Thanks!

Could you please tell me the steps how to fix memory corruption related issues.

In my case due to memory corruption the behaviour of the object has changed instead of crashing.

I am very new to this. please

1 solution

The normal problem with this kind of thing is that you create the pointers by referencing local variables - since these are created on the stack, they are not maintained once you leave the function. If you want them to persist, the you need to create them on the heap, using the new keyword, or the malloc function.
 
Share this answer
 
Comments
dharmakiran 22-Nov-11 8:57am    
Thanks!

In my senario it will not help full.

is there any good tools to identify the memory corruption issues?

Could you please share me your exp on memory corruption?

I am very new to this...
OriginalGriff 22-Nov-11 9:37am    
Best suggestion: put a breakpoint in the constructor, and single step through, looking at what your code is doing.
Sorry if that sounds vague, but I have no idea what your code looks like, so I can't be any more precise!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900