簡體   English   中英

sigc :: mem_fun並從類方法傳遞參數

[英]sigc::mem_fun and pass params from a class method

在gtkmm中,我可以在構造函數中使用如下所示的內容:

// Gtk::ImageMenuItem *iQuit;
iQuit->signal_activate().connect (sigc::mem_fun (*this, &FormUI::on_quit_activated) );

但是我想使用一種方法來設置項目的屬性,例如:

void FormUI::SetItemProps (Gtk::ImageMenuItem *i, const Glib::ustring& _l, ?what should I put here?)
{
i->set_use_stock (true);
i->set_label (_l);
i->signal_activate().connect (sigc::mem_fun (*this, ???) ); <-- what to pass there
}

所以我可以在構造函數中使用類似這樣的東西:

SetItemProps (iQuit, "gtk-quit", &FormUI::on_quit_activated);

有什么想法嗎?

您可能會喜歡使用typedef:

typedef void (FormUI::*function_ptr)();
void FormUI::SetItemProps (Gtk::ImageMenuItem *i, const Glib::ustring& _l, function_ptr fun)
{
    i->set_use_stock (true);
    i->set_label (_l);
    i->signal_activate().connect (sigc::mem_fun (*this, fun) );
}

並且方法on_quit_activated()必須是聲明的類型。

打電話使用

SetItemProps (iQuit, "gtk-quit", &FormUI::on_quit_activated);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM