class myClass
{
public:
.....
inline int GetValue() {return myValue;}
.....
protected:
.....
int myValue;
}
.....
.....
int a;
myClass *cls = ... something valid
.....
a = cls->GetValue();
.....
In the watch window myValue inside cls is ok, but a has some random data (most of the times 0xcdcdcdcd).
I have lots of inline access functions but only a few are having this problem.
The only solution was to remove the "inline" and to move the function's body into a cpp.
Am I the only one with this problem ? Or anyone knows any little work around ?
Thanks.
Weird problem in C++ with .NET 2003
I've tryed to port one of my projects from Visual Studio 6 to Visual Studio .NET 2003. All went ok but when I've ran the project there were some crashes (apparently without any reason).
All problems were somethilg like that:
are you initializing myValue to something at startup? Debug mode does this for you, while release doesn't.
Quote:Original post by c0mas
In the watch window myValue inside cls is ok, but a has some random data (most of the times 0xcdcdcdcd).
That looks suspiciously like the default value that the debug release will set in order to catch uninitialized values. Sounds like you aren't calling a constructor, or else you aren't setting myValue within that constructor. More code would help clarify.
CM
Yes, I initialize it and it happends on debug and release too.
In some cases (when I return a pointer) the value is not 0xcdcdcdcd, but a strange value.
Also I've tryed to make the member public and use it directly ... the same result.
One more failed try was to use:
It only worked if I used:
Or if I move the function code inside a .cpp file (and remove the inline modifier).
Im sure that the value is set ok (the debugger shows me the right value, or if a make a trace within "cls" I get the right value). And of course rebuild all does not help.
Also I've tryed to see if it doesn't link with VC6 lib's (I've deleted them and relinked the project) same result.
In some cases (when I return a pointer) the value is not 0xcdcdcdcd, but a strange value.
Also I've tryed to make the member public and use it directly ... the same result.
One more failed try was to use:
inline void SetGetValue(int &val) {val = myValue;}
It only worked if I used:
static int g_myValue = 0;.....g_myValue = myValue; // somwhere in myClass.....extern int g_myValue;.....int a;a = g_myValue;
Or if I move the function code inside a .cpp file (and remove the inline modifier).
Im sure that the value is set ok (the debugger shows me the right value, or if a make a trace within "cls" I get the right value). And of course rebuild all does not help.
Also I've tryed to see if it doesn't link with VC6 lib's (I've deleted them and relinked the project) same result.
Try pasting a little more consistent code, for all we know you could be housing evil marsians inside those dots.
As the others said, 0xCDCDCDCD most commonly means that the variable has not been initialized, try explicitly setting it first and so on.
As the others said, 0xCDCDCDCD most commonly means that the variable has not been initialized, try explicitly setting it first and so on.
Well, it's not, unless that's the value you set it to.
Either that or it's not pointing to something that is valid anymore.
Either that or it's not pointing to something that is valid anymore.
Uuuuse the Debugger. See if the pointer is changing. If not, put a data breakpoint on mydata and see where it fires.
Well, I've checked with the debugger.
cls it's ok and I can call any function in it. More than that, if I enter (with the debugger) in a cls->Function, myValue it's ok.
I've just realized that I have another thing to try: I'll check if the address(or offset from the address of cls) of myValue is the same.
cls it's ok and I can call any function in it. More than that, if I enter (with the debugger) in a cls->Function, myValue it's ok.
I've just realized that I have another thing to try: I'll check if the address(or offset from the address of cls) of myValue is the same.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement