This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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);
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]