Difference between revisions of "CPP/Boost/Signals/ClassMemberWithParameters"
From ProgrammingExamples
< CPP
Daviddoria (Talk | contribs) (Created page with '==ClassMemberWithParameters.cpp== <source lang="cpp"> #include <boost/signal.hpp> #include <boost/bind.hpp> #include <iostream> class InteractorStyle { public: boost::signal<…') |
Daviddoria (Talk | contribs) m |
||
(One intermediate revision by the same user not shown) | |||
Line 20: | Line 20: | ||
Form() | Form() | ||
{ | { | ||
− | MyInteractorStyle.UpdateData.connect(boost::bind(&Form::DataUpdated, this)); | + | MyInteractorStyle.UpdateData.connect(boost::bind(&Form::DataUpdated, this, _1)); // _1 is a placeholder for the 1st argment |
} | } | ||
Latest revision as of 12:28, 1 February 2011
ClassMemberWithParameters.cpp
#include <boost/signal.hpp> #include <boost/bind.hpp> #include <iostream> class InteractorStyle { public: boost::signal<void (float)> UpdateData; }; class Form { private: InteractorStyle MyInteractorStyle; float Data; public: Form() { MyInteractorStyle.UpdateData.connect(boost::bind(&Form::DataUpdated, this, _1)); // _1 is a placeholder for the 1st argment } void DataUpdated(float data) { this->Data = data; std::cout << "Data updated!" << std::endl; } void TellInteractorToUpdate() { // This is just for the demo - it would really be caused by a user event MyInteractorStyle.UpdateData(5.1); } void OutputData() { std::cout << "Data: " << Data << std::endl; } }; int main() { Form MyForm; MyForm.TellInteractorToUpdate(); // This is just for the demo - it would really be caused by a user event MyForm.OutputData(); }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) Project(ClassMemberWithParameters) ADD_EXECUTABLE(ClassMemberWithParameters ClassMemberWithParameters.cpp) TARGET_LINK_LIBRARIES(ClassMemberWithParameters boost_signals-mt)