How to add a conditional breakpoint in Visual C ++

I want to add a break condition to my code in VC ++ Express 2005, so that a break point is only triggered if the local variable meets the specified criteria. eg.

bool my_test(UIDList test_list) {
    foo(test_list);
    bar(test_list); // I have a breakpoint here, but only want it to trigger if test_list.Length() > 0
    print(test_list);
}

By right-clicking on my breakpoint and selecting "Condition ...", I found a dialog box that appears to do what I want, however everything that I try to enter in the text box leads to the following error:

Unable to evaluate breakpoint condition: CX0052: Error: member function missing

I tried the help documentation but could not find the answer. I hope someone from VC ++ can point me in the right direction ...

I previously tried to switch to a later version of VC ++ Express, but the project did not import cleanly. Due to the complexity of the project and my current time scale, I cannot consider upgrading as a solution at the moment.

+5
source share
3 answers

use DebugBreak (); Function:

bool my_test(UIDList test_list) {
    foo(test_list);
    if (bar(test_list) /* or whatever check :) */) // I have a breakpoint here, but only want it to trigger if test_list.Length() > 0
        DebugBreak();
    }
    print(test_list);
}

Or you can always use assert (expression)

bool my_test(UIDList test_list) {
    foo(test_list);
    bar(test_list);
    assert(test_list.Length() > 0); // will break here
    print(test_list);
}
+8
source

VS - - , , .. . , , , , , .
,

test_list.Length() > 0  

-

test_list.m_nLength > 0

( var).

(EDIT) msdn, , . , -

' . , -.

, -, "Length()" - , , :

' , , .

+10

, . , . - .

<>
bool my_test (UIDList test_list) {
 Foo (test_list);
 int  = test_list.Length();
  (test_list);//     ,   ,   ,  test_list.Length()> 0
 print (test_list);
}
Code>

Put a conditional breakpoint on the value i here, and you should be fine.

+4
source

All Articles