請問下列程式中的委派
我看不董這一段↓
===============================================================
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