How to debug C++ functor in gdb?

Peng Yu pengyu.ut@gmail.com
Sun Oct 29 21:01:00 GMT 2006


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



More information about the Gdb mailing list