This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
How to debug C++ functor in gdb?
- From: "Peng Yu" <pengyu dot ut at gmail dot com>
- To: gdb at sourceware dot org
- Date: Sun, 29 Oct 2006 15:01:34 -0600
- Subject: How to debug C++ functor in gdb?
Hi,
I have a test program using functor below.
I set a break point at the line indicated in the comment. Then I call
the following command in gdb. It failed. Is there any way that I can
call the functor _f?
(gdb) p _f(10)
Couldn't find method functor<function<int> >::_f
Thanks,
Peng
#include <functional>
template <typename F>
class functor {
public:
functor(const F &f) : _f(f) { }
typename F::result_type operator()(double x) const { return
_f(static_cast<int>(x)); }//set break point here in gdb
private:
F _f;
};
template <typename T>
struct function : public std::unary_function<T, double> {
double operator()(T x) const { return static_cast<double>(x); }
};
int main() {
functor<function<int> > g((function<int>()));
g(1.1);
}