I have the following code
#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;
}
I can compile it and get the correct result, but I have problems when I try to debug it. Obviously, the compiler can figure out how to perform a binary operation, but the debugger cannot. My compiler version is 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)
Am I doing something wrong or is there a problem with the debugger?
source
share