Click here to Skip to main content
15,886,799 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to declare pointer to member function Pin
wsauer27-Aug-10 18:12
wsauer27-Aug-10 18:12 
GeneralRe: How to declare pointer to member function Pin
Aescleal27-Aug-10 20:19
Aescleal27-Aug-10 20:19 
GeneralRe: How to declare pointer to member function Pin
Niklas L27-Aug-10 21:15
Niklas L27-Aug-10 21:15 
GeneralRe: How to declare pointer to member function Pin
Aescleal27-Aug-10 22:21
Aescleal27-Aug-10 22:21 
AnswerRe: How to declare pointer to member function Pin
«_Superman_»27-Aug-10 18:20
professional«_Superman_»27-Aug-10 18:20 
AnswerRe: How to declare pointer to member function Pin
Paul Michalik28-Aug-10 0:55
Paul Michalik28-Aug-10 0:55 
GeneralRe: How to declare pointer to member function Pin
Aescleal28-Aug-10 4:52
Aescleal28-Aug-10 4:52 
GeneralRe: How to declare pointer to member function Pin
Paul Michalik28-Aug-10 9:52
Paul Michalik28-Aug-10 9:52 
Aescleal wrote:
This sort of thing tends to be horses for courses - people who think in OO terms are likely to grab onto using interfaces for everything while people who think in compositional or functional terms will tend to reach for templates.


It's not exactly the same, if you don't mind... With functors of that kind you get a first class object representation of a function, basically grabbing the best of both worlds. If you go the pure OO-way , you define an ISubscriber and end up with a variation of the observer pattern. Then, the components are loosely coupled (by sharing the ISubscriber definition) but they are coupled: The only way to subscribe for the Publisher service is to feed him with polymorphic ISubscriber instances.

With the approach sketched above, the Publisher is not coupled to a consumer of it's services at all - the subscriber only needs to satisfy the signature of Delegate. So the "wire up" part could look like this:

bool LooseSubscriber() {
  std::out << "LooseSubscriber called" << std::endl;
  return true;
}

int main() {
 Publisher tPub;
 Subscriber tSubs(0);
 // connect to "Subscriber" instance
 tPub.Connect
  (bind(mem_fn(&Subscriber::FileMenu), tSubs));
 // connect to "LooseSubscriber" function
 tPub.Connect
  (LooseSubscriber);
 // ...and if you're on stereoids:
 tPub.Connect
  ([] (void)->bool { 
    std::out << "lambda Subscriber called" << std::endl;
    return true; 
  });
}

GeneralRe: How to declare pointer to member function Pin
Aescleal28-Aug-10 11:10
Aescleal28-Aug-10 11:10 
GeneralRe: How to declare pointer to member function Pin
Paul Michalik28-Aug-10 21:40
Paul Michalik28-Aug-10 21:40 
QuestionAfxGetMainWnd() returns the window of another application!!!! Pin
VCSharp00727-Aug-10 0:08
VCSharp00727-Aug-10 0:08 
Questionwindow controls are not getting resized while dragging the window Pin
arun_pk27-Aug-10 0:04
arun_pk27-Aug-10 0:04 
AnswerRe: window controls are not getting resized while dragging the window Pin
Cool_Dev27-Aug-10 2:24
Cool_Dev27-Aug-10 2:24 
AnswerRe: window controls are not getting resized while dragging the window Pin
David Crow27-Aug-10 6:46
David Crow27-Aug-10 6:46 
QuestionProblem in binary file writing Pin
ganesh_IT26-Aug-10 23:52
ganesh_IT26-Aug-10 23:52 
AnswerRe: Problem in binary file writing Pin
Sauro Viti27-Aug-10 0:01
professionalSauro Viti27-Aug-10 0:01 
QuestionBinary file read writing problem Pin
ganesh_IT26-Aug-10 23:46
ganesh_IT26-Aug-10 23:46 
AnswerRe: Binary file read writing problem PinPopular
CPallini26-Aug-10 23:51
mveCPallini26-Aug-10 23:51 
AnswerRe: Binary file read writing problem Pin
ThatsAlok29-Aug-10 20:59
ThatsAlok29-Aug-10 20:59 
QuestionGUI Pin
T.RATHA KRISHNAN26-Aug-10 20:10
T.RATHA KRISHNAN26-Aug-10 20:10 
AnswerRe: GUI Pin
Niklas L26-Aug-10 22:00
Niklas L26-Aug-10 22:00 
GeneralRe: GUI Pin
T.RATHA KRISHNAN26-Aug-10 23:05
T.RATHA KRISHNAN26-Aug-10 23:05 
GeneralRe: GUI Pin
Niklas L26-Aug-10 23:22
Niklas L26-Aug-10 23:22 
GeneralRe: GUI Pin
T.RATHA KRISHNAN26-Aug-10 23:29
T.RATHA KRISHNAN26-Aug-10 23:29 
GeneralRe: GUI Pin
Niklas L27-Aug-10 1:09
Niklas L27-Aug-10 1:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.