c++ - gdb:如何调用 operator char const*()?

标签 c++ gdb operators

我的类(class)有 operator const char*() const { return "foo";

我让 gdb 7.12.1-48.el7 在变量 q 属于此类的地方停止。

我键入 p q.,当我按下该键时,我会看到它的所有方法和成员的完整列表,包括 operator char const*

但是,我收到了对这些命令的响应。

(gdb) p q.operator char const*()
Couldn't find method MyClass::operatorconst char *

(gdb) p q.operator char const*
There is no member or method named operatorconst char *.

(gdb) p q.(operator char const*)
A syntax error in expression, near `(operator char const*)'.

(gdb) p q.(operator char const*)()
A syntax error in expression, near `(operator char const*)()'.

关于如何调用此方法有什么想法吗?

最佳答案

您可以只使用隐式转换。对我来说,p (const char*)q 在 gdb 8.2.1 中工作:

(gdb) p (const char*)q
$2 = 0x7ffffffedaf0 "qwer"
(gdb)

关于c++ - gdb:如何调用 operator char const*()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64119531/

相关文章:

emacs - 如何关闭GUD中的*输入/输出*缓冲区

c++ - 添加两个字符列表

java - && 和 || while循环中的问题

javascript - C# 使用 + 运算符的奇怪行为

C++ 在自定义类/结构数组的构造函数中获取数组键?

c++ - 当我们进行向下转型时内部会发生什么?

c++ - 尽管覆盖仍编译错误

profiling - 自动化 gdb : show backtrace every 10 ms

linux - 如何使用GDB提取结构成员的值

c++ - Operator=声明问题