template for delegates  
Author Message
Ivan F. Skripov





PostPosted: Visual C++ Language, template for delegates Top

I have a code:

#pragma once

namespace iReader {

delegate void BeginHandler();

delegate void EndHandler();

//template <class TEvent> < TROUBLE IS HERE >

delegate void TransitionHandler(int aPrevState, int aCurrentState);

template <typename TEvent>

ref class CFSMTable {

public:

CFSMTable(unsigned int aEventsCount, unsigned int aStatesCount) {

iStates = gcnew array<TEvent, 2>(aEventsCount, aStatesCount);

}

protected:

array<TEvent, 2>^ iStates;

};

};

When I uncomment //template <class TEvent> I have an error

f:\work\.net explorer\ireader\FiniteStateMachine.h(11) : error C3755: 'TransitionHandler': a delegate may not be defined

f:\work\.net explorer\ireader\FiniteStateMachine.h(11) : fatal error C1903: unable to recover from previous error(s); stopping compilation

As I undestand form MSDN article ( http://www.hide-link.com/ ) it means that I not simply declared but already define the template.

How it could be It’s only declaration.

Cound you give me a clue to this problem.

Thank you




Visual C++4  
 
 
Mike Danes





PostPosted: Visual C++ Language, template for delegates Top

I can't say I have seen this stated somewhere in docs but: "you cannot create a template delegate" is what's happening.

You need to use generics for that:

generic <class TEvent>

delegate void TransitionHandler(int aPrevState, int aCurrentState);


 
 
Ivan F. Skripov





PostPosted: Visual C++ Language, template for delegates Top

Thanks a lot Mike. This variant is work fine.