Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I use Visual Studio 2012 Express to debug a 64-bit app. Let's say both 'foo' and 'bar' are some member functions of a class C.

'foo' looks like:

void foo() {
    bar();    // change to this->bar() works!
}

My program crashed because 'this' pointer is changed when it went inside 'bar'. The problem can be fixed by changing to 'this->bar()'.

Any idea how I should debug this problem? Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
344 views
Welcome To Ask or Share your Answers For Others

1 Answer

You mean that the following code works?

void foo() {
    this->bar();    // instead of bar()
}

So, presuming foo() is a member function that calls another member function bar() for the same object, check two things: (1) whether there is another non-member function bar() having same signature of member function bar(), if so exist, change the non-member function name op always qualify with this-> for member function call as a good programming practice (2) When you call foo() for some object instance or pointer to object instance, check whether the object has been allocated and initialized properly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...