Arsen Zahray
Arsen Zahray

Reputation: 25307

How do I add a delegate to event in managed c++ 2010?

I've got following code in c#

public class Shedluer
{
    public delegate void TaskCompletedDelegate(ulong taskId);
    public static event TaskCompletedDelegate OnTaskCompleted;
}

Here's how I'm trying to use it in c++.net:

shedluer->OnTaskCompleted+=gcnew Shedluer::TaskCompletedDelegate(OnTaskFinished);

where OnTaskFinished is a non-static method declared inside a ref class.

I've seen a bunch of examples for c++.net 2007, but those won't compile in vs 2010.

How do I add a delegate to event in managed c++ 2010?

Upvotes: 2

Views: 759

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564641

Supposing the OnTaskFinished is in the current class, and that ref class is of type MyClass. In that case, you'd write:

shedluer->OnTaskCompleted += gcnew Shedluer::TaskCompletedDelegate(this, &MyClass::OnTaskFinished);

Upvotes: 2

Related Questions