C++ (Qt)#include <QApplication> #include <QDebug>#include <QWidget>#include <QVector> int main(int argc, char *argv[]){ QApplication a(argc, argv); QVector<QWidget*> v; v.push_back(new QWidget()); v.push_back(new QWidget()); v.push_back(new QWidget()); v.push_back(new QWidget()); v.push_back(new QWidget()); for_each( v.begin(), v.end(), std::bind1st( std::mem_fun( &QWidget::setVisible ), 0) ); //AAAAARRRGGHHHHH! for( int i = 0; i < v.size(); ++i ) { qDebug() << "Item " << i << ", visibility " << v[i]->isVisible(); } return a.exec();}
C++ (Qt)... for_each( v.begin(), v.end(), std::bind1st( std::mem_fun( &QWidget::setVisible ), 0) ); //AAAAARRRGGHHHHH!...
QVector<QWidget*> v;...тут заполнили... foreach (QWidget *w, v) { ... w->setVisible(); ... }
C++ (Qt)void visible_helper( QWidget *w, bool val ){ w->setVisible( val );} int main(int argc, char *argv[]){ ... for_each( v.begin(), v.end(), std::bind2nd( std::ptr_fun( &visible_helper ), false ) ); ...}