Boost: signals2 learning game-constellation gas station

Source: Internet
Author: User

Using the Win32 console program and the boost: signals2 library, you can also write interesting demo games.

Post the code first and then explain it:

# Include "stdafx. H "<br/> # include <iostream> <br/> # include <boost/signals2.hpp> <br/> using namespace STD; <br/> typedef int status; <br/> Status capriconstation (const int power, const int enhancefactor) <br/>{< br/> If (power> = 10) <br/> {<br/> int nnewpower = power * enhancefactor; <br/> cout <"your power has alreay been enhaned by capriconstation, now is: "<nnewpower <Endl; <br/> return 1; <br/>}< br/> Else <br/> {<br/> cout <"capriconstation cannot enhance your power, please goto next station! /N "; <br/> return 0; <br/>}< br/> Status scorpiostation (const int power, const int enhancefactor) <br/>{< br/> If (power> 0 & Power <10) <br/>{< br/> int nnewpower = power * enhancefactor; <br/> cout <"your power has alreay been enhaned by scorpiostation, now is:" <nnewpower <Endl; <br/> return 1; <br/>}< br/> else <br/> {<br/> cout <"scorpiostation cannot enhance your power, please goto next stat Ion! /N "; <br/> return 0; <br/>}< br/> Status recyclestation (const int power, const int enhancefactor) <br/> {<br/> If (power <0) <br/> {<br/> cout <"your left power is not normal! You are recycled by recyclestation! /N "; <br/> cout <" you are dead! /N "; <br/> return 0; <br/>}< br/> // combiner: distributerequestsystem <br/> typedef int fullfilledrequest; <br/> struct distributerequestsystem <br/>{< br/> typedef fullfilledrequest result_type; <br/> template <typename inputiter> <br/> result_type operator () (inputiter first, inputiter last) <br/>{< br/> while (first! = Last) <br/>{< br/> If (nsuccessstatus = * First) <br/> return nsuccessstatus; <br/> + first; <br/>}< br/> return 0; <br/>}< br/> const static int nsuccessstatus = 1; <br/> }; <br/> int main () <br/> {<br/> boost: signals2: Signal <int (const int, const INT), distributerequestsystem> sig_5; <br/> sig_5.connect (& capriconstation); <br/> sig_5.connect (& scorpiostation); <br/> sig_5.connect (& recyclestation ); <br/> cout <"the responding status:" <sig_5 (8, 5) <Endl; <br/> cout <"the responding status: "<sig_5 () <Endl; <br/> cout <" the responding status: "<sig_5 (-) <Endl; <br/> return 0; <br/>} 

Running result:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.