close
Blogtrottr
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 發問中
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 發問中 
clr 委派問題
Jul 23rd 2013, 21:34

請問下列程式中的委派
我看不董這一段↓
===============================================================
MyTimer->TimeOverEvent += gcnew TimerEventHandler(MyEvent,&EventClass::Warm);
===============================================================
請問"+="
這部分可以拆開嗎?
拆開會變時麼樣子?
能不能解釋一下原理0.0
勞煩了~謝謝

==========================原程式===================================
#include "stdafx.h"
#include "Timer.h"
using namespace System;

ref class EventClass
{
public:
void Warm(int vSpeed)
{ Console::WriteLine("發生秒數 {0} 的事件", vSpeed); }
void Warm2(int vSpeed)
{ Console::WriteLine("也可以連續觸發其它事件"); }
};

int main(array<System::String ^> ^args)
{
Timer^ MyTimer = gcnew Timer();
EventClass^ MyEvent = gcnew EventClass();

MyTimer->TimeOverEvent += gcnew TimerEventHandler(MyEvent,&EventClass::Warm);
MyTimer->TimeOverEvent += gcnew TimerEventHandler(MyEvent,&EventClass::Warm2);
MyTimer->Second = 10;
Console::WriteLine("現在秒數={0}", MyTimer->Second);
Console::WriteLine("---------------------");
MyTimer->DeCrease(15); //減 15 秒後觸發 TimeOverEvent 事件
Console::WriteLine("現在秒數={0}", MyTimer->Second);
Console::Read();
return 0;
}

================================================================
#include "stdafx.h"
using namespace System;

public delegate void TimerEventHandler(int n);
ref class Timer
{
private:
int m_Second;
public:
event TimerEventHandler^ TimeOverEvent;
property int Second
{
int get() { return m_Second; }
void set(int value)
{
if (value < 0)
{
TimeOverEvent(value);
value = 0;
}
m_Second = value;
}
}
void DeCrease(int n)
{ this->Second = this->Second - n; }

};
================================================================

This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers. Five Filters recommends: 'You Say What You Like, Because They Like What You Say' - http://www.medialens.org/index.php/alerts/alert-archive/alerts-2013/731-you-say-what-you-like-because-they-like-what-you-say.html

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed, or manage all your subscriptions
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 qhhwzod5rw3gd 的頭像
    qhhwzod5rw3gd

    線上遊戲排行榜2013/2014,進擊的巨人線上看,candy crush saga外掛,正妹寫真三圍

    qhhwzod5rw3gd 發表在 痞客邦 留言(0) 人氣()