Reputation: 327
How can I port this code (c++) to c#?
template <class entity_type>
class State {
public:
virtual void Enter(entity_type*) = 0;
virtual void Execute(entity_type*) = 0;
virtual void Exit(entity_type*) = 0;
virtual ~State() { }
};
Upvotes: 2
Views: 272
Reputation: 6155
Assuming that really is a purely abstract base class, which is what it looks like:
interface State<T>
{
void Enter(T arg);
void Execute(T arg);
void Exit(T arg);
};
The exact argument passing convention is awkward though. Without knowing exactly what you want to do it is hard to say exactly what you should do in C#. Possibly, void FunctionName(ref T arg)
might be more appropriate.
Upvotes: 6
Reputation: 327
public abstract class State<entity_type>
{
public abstract void Enter(entity_type obj);
public abstract void Execute(entity_type obj);
public abstract void Exit(entity_type obj);
}
This seems to work :D
Upvotes: 1
Reputation: 1573
you can write like this
abstract class State<T> : IDisposable where T : EntityType
{
public abstract void Enter(T t);
public abstract void Execute(T t);
public abstract void Exit(T t);
public abstract void Dispose();
}
fix your T to EntityType class.
Upvotes: -1
Reputation: 8881
Some thing of the sort:
interface State<T> : IDisposable
{
void Enter(T t);
void Execute(T t);
void Exit(T t);
}
Upvotes: 3