I have a getter object that is suppose to return a value of type bool(default value is false). When a certain condition is met, the return value for the getter object is suppose to change to true. When I call the getter object in another function, however, the value remains false, despite the condition being met.
I did some research and I found out that the getter object is suppose to return a reference value. I did that and I still am having the same problem. Here is some pseudo code
1 2 3 4 5 6 7 8 9 10 11
// A.h
class A
{
private:
bool restart;
public:
bool& GetRestart();
};
// B.cpp
void B::check()
{
cout << A.GetRestart() << endl; // Value is always 0(false), even when
} // the condition above,if mouse clicked, is met(restart should turn to true)
Some insight would be appreciated. If anything else is needed let me know.
For built-in types it doesn't really matter if you return a reference to a data member or not, but anyway:
You should probably show actual compilable code so that we can see where the problem is. What is your B class (or namespace?) and how does it relate to your A class? Are you even sure your if statement is being returned true? A is the name of a class, where do you define A as being an object of your A class? Is it a data member of your B class?
Printing as a debugging method does have certain advantages.
* It's useful to narrow down the failure of a long-running procedure. Imagine having to skip 500 breakpoint hits to get to the one you care about.
* It's often useful when the presence of a debugger affects program behavior.
Conditional breakpoints have limited expressive power, or the exact condition that indicates failure may not be entirely clear. Conditional breakpoints also make the debuggee much slower, often too slow to be useful.