我有多个控件,如下所示:
deque<wxTextCtrl*> dequeEdit;
deque<wxStaticText*> dequeText;
deque<wxComboBox*> dequeCombo;
所有这些控件都继承自wxWindow,wxWindow具有Show方法。我想一次显示(或隐藏)整个双端队列,而不需要每个双端队列使用多种方法。怎么可能做到呢?
我正在考虑为每个控件制作wxWindow的双端队列,这样我就可以编写方法
ShowDeque(deque<wxWindow*> deque)
所以展示会很容易,但另一方面,如果我想与例如合作组合框,我必须将其输入回 wxComboBox。 还有其他可能性吗?谢谢。
最佳答案
用途:
for_each(dequeEdit.begin(), dequeEdit.end(), mem_fun(&wxWindow::Show));
与任何其他双端队列相同。
或者封装在一个函数中:
template <class Deque>
void showAll(const Deque& dequeObj)
{
using namespace std;
for_each(dequeObj.begin(), dequeObj.end(), mem_fun(&wxWindow::Show));
}
showAll(dequeEdit);
std::for_each
: http://en.cppreference.com/w/cpp/algorithm/for_eachstd::mem_fun
: http://en.cppreference.com/w/cpp/utility/functional/mem_fn
关于c++ - C++中对象的继承和双端队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12673253/