GDB 不会执行二进制操作
gdb will not perform binary operation
>我有以下代码
#include <iostream>
using namespace std;
class Point2D
{
public:
double x;
double y;
Point2D(double x_i,
double y_i):
x(x_i), y(y_i) {}
};
Point2D operator+(const Point2D& p1,
const Point2D& p2)
{
return Point2D(p1.x+p2.x, p1.y+p2.y);
}
Point2D operator*(double s, const Point2D& p)
{
return Point2D(p.x*s,p.y*s);
}
ostream& operator<<(ostream& os, const Point2D& p)
{
os << p.x << " " << p.y << endl;
return os;
}
int main(void)
{
const Point2D p1(2,3);
const Point2D p2(5,4);
cout << 0.5*(p1+p2) << endl;
return 0;
}
我可以编译它并获得正确的结果,但是当我尝试调试它时遇到了麻烦。显然,编译器可以弄清楚如何执行二进制操作,但调试器不能。我的编译器版本是g++(Ubuntu 4.9.1-16ubuntu6)4.9.1。
$ g++ -g ./for_stack_overflow.cpp && gdb ./a.out
GNU gdb (Ubuntu 7.8-1ubuntu4) 7.8.0.20141001-cvs
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...done.
(gdb) break 41
Breakpoint 1 at 0x400b90: file ./for_stack_overflow.cpp, line 41.
(gdb) r
Starting program: /home/almog/Documents/a.out
3.5 3.5
Breakpoint 1, main () at ./for_stack_overflow.cpp:41
41 return 0;
(gdb) print 0.5*(p1+p2)
Can't do that binary op on that type
(gdb)
是我做错了什么还是调试器有问题?
p1+p2 等效于调用重载运算符+方法,但此运算符到方法的边界是在编译时完成的。 因此 GDB 不知道要调用哪个方法。
相关文章:
- STL 用户定义的二进制操作
- C++二进制文件 I/O 操作速度变慢.数据库如何处理二进制文件?
- 二进制模式 + 格式化文本操作或文本模式 + 二进制数据操作 - 有意义吗?
- 二进制搜索树操作程序错误:分割故障(核心倾倒)
- 如何在我的进程中运行的二进制文件中注册操作和内核
- 为什么C++标准指定有符号整数在具有混合符号的二进制操作中强制转换为无符号整数
- 重载二进制操作的正确方法
- 无效操作数以二进制读取结构的阵列
- 了解C++位操作中的二进制转换实现
- "constexpr"通过二进制操作减少"std::array"
- 警告 639:二进制操作中类型 'uint64' 的强类型不匹配
- 二进制搜索操作
- 二进制与文本模式下的文件操作 -- 性能问题
- 如何在C++中操作和表示二进制数
- 重新创建具有最少"XOR"操作的二进制矩阵
- GDB 不会执行二进制操作
- 如何在两个容器的元素之间执行成对二进制操作?
- 二进制操作的示例程序
- 在c++中将包含二进制操作的字符串转换为双精度类型
- 十六进制和二进制操作