简体   繁体   中英

Is there a C++ equivalent to objective-c's -debugDescription method for Xcode 7?

In Objective-C you can add a method called -debugDescription to your classes that return a string. The Xcode debugger will call this method to display the value of the class in the debugger. Is there an equivalent to this in C++?

No (not with the functionality that the plain language provides). C++ has no so called root object compared to Objective-C's NSObject (or NSProxy ). For such metainfo/introspection/reflection you have to use libraries like Qt or others that support such features.

While not as universal, you can add your own description methods to certain classes of interest and po the method at runtime from the console.

Eg

std::string your_class::desc()
{
    return "test";
}

(lldb) po ((your_class*)0x000000010072adf8)->desc()
"test"

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