class Delegate : public QItemDelegate{Q_OBJECTpublic: Delegate(QObject *parent = 0); QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem & option ,const QModelIndex &index) const; ... ... private: QWidget *(*myfunc)(QWidget *parent, const QStyleOptionViewItem & option, const QModelIndex &index) const; };
delegate.h:50:92: error: 'const' and 'volatile' function specifiers on 'myfunc' invalid in field declaration
Delegate::Delegate(QObject *parent):QItemDelegate(parent){ myfunc =createEditor;}
delegate.cpp: In constructor 'Delegate::Delegate(QObject*)':delegate.cpp:32:11: error: argument of type 'QWidget* (Delegate::)(QWidget*, const QStyleOptionViewItem&, const QModelIndex&)const' does not match 'QWidget* (*)(QWidget*, const QStyleOptionViewItem&, const QModelIndex&)'
C++ (Qt)#include <functional>#include <string>#include <iostream> class my_class {public: my_class() { f_ptr = &my_class::print; } void message() { f_ptr(this, "Hello member function"); } void print(const std::string &msg) { std::cout << msg << std::endl; } private: std::function<void (my_class*, const std::string& )> f_ptr;}; int main() { my_class mc; mc.message(); return 0;}