简体   繁体   中英

Cant set breakpoint in C++/Objective-C++ code

I'm trying to set a breakpoint in my objective c++ ( I think its called) code.

I've used #ifdef _cplusplus and #endif to wrap the code, but when I go to set a breakpoint in it, it breaks on the end of the method body, and none of the code in the body is run.

错误的断点:/

I've simplified the code I had, but I expect at least to see numbers being printed in the console because of the cout .

The file has the extension .mm too. I'm new to mixing C++ and Objective-C. Anything I've missed?

#ifdef is a preprocessor directive - in short, this means that without _cplusplus being #define d somewhere, your debugger is smart enough to say Hey, this is dead code - don't even try to debug it .

Preprocessor directives are lines included in the code of programs preceded by a hash sign (#). These lines are not program statements but directives for the preprocessor . The preprocessor examines the code before actual compilation of code begins and resolves all these directives before any code is actually generated by regular statements.

These preprocessor directives extend only across a single line of code. As soon as a newline character is found, the preprocessor directive is ends. No semicolon (;) is expected at the end of a preprocessor directive. The only way a preprocessor directive can extend through more than one line is by preceding the newline character at the end of the line by a backslash ().

These are super useful, and for a common example have a quick look at Include Guards . As a test to see what I mean, try adding #define _cplusplus directly above the #ifdef and try again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM