#include <QtCore/QCoreApplication>
#include <boost/bind.hpp>
#include <boost/function.hpp>
class button
{
public:
boost::function<void()> onClick;
boost::function<void(int ,double)> onClick2;
};
class player
{
public:
void play(int i,double o){}
void stop(){}
};
button playButton, stopButton;
player thePlayer;
void connect()
{
//error C2298: 'return' : illegal operation on pointer to member function expression
playButton.onClick2 = boost::bind(&player::play, &thePlayer);
stopButton.onClick = boost::bind(&player::stop, &thePlayer);
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
connect();
return a.exec();
}
6
A
उत्तर
13
boost::bind(&player::play, &thePlayer)
आप दो तर्क के लिए प्लेसहोल्डर उपयोग करने की आवश्यकता:
boost::bind(&player::play, &thePlayer, _1, _2)
प्लेसहोल्डर आप कहते हैं कि करने के लिए अनुमति "मैं केवल कुछ तर्क बाध्यकारी कर रहा हूँ, दूसरी बहस बाद में उपलब्ध कराया जाएगा।"
2
और तुम पोर्टेबल कोड बनाने चाहते हैं - निर्दिष्ट प्लेसहोल्डर के नाम स्थान सीधे:
boost::bind(&player::play, &thePlayer, ::_1, ::_2); // Placeholders of boost::bind are placed in global namespace.