1

In C#:

public sealed class StateMachine<TState, TTrigger>

I'd like to write a C++ equivalent.

Xeo
  • 126,658
  • 49
  • 285
  • 389
CodingHero
  • 2,715
  • 5
  • 26
  • 41

3 Answers3

3

Like this:

template <typename TState, typename TTrigger>
class StateMachine
{
    //...
};
Stuart Golodetz
  • 19,702
  • 4
  • 49
  • 80
1

This site has a pretty good explanation of how to make template classes. Example:

// function template
#include <iostream>
using namespace std;

template <class T>
T GetMax (T a, T b) {
  T result;
  result = (a>b)? a : b;
  return (result);
}

int main () {
  int i=5, j=6, k;
  long l=10, m=5, n;
  k=GetMax<int>(i,j);
  n=GetMax<long>(l,m);
  cout << k << endl;
  cout << n << endl;
  return 0;
}

Use this in combination with this previous Stack Overflow question to achieve the sealed aspect of the class.

Community
  • 1
  • 1
vette982
  • 4,572
  • 8
  • 33
  • 40
0

You could use what Stuart and Xeo proposed, and if you want to make the class sealed here is link that explains how to do it.

EDITED: this is even better.

Stuart Golodetz
  • 19,702
  • 4
  • 49
  • 80
Sergey Kucher
  • 4,120
  • 5
  • 27
  • 47