【发布时间】:2012-02-03 13:21:44
【问题描述】:
在 C# 中:
public sealed class StateMachine<TState, TTrigger>
我想写一个 C++ 等价物。
【问题讨论】:
-
你会想要改写它
在 C# 中:
public sealed class StateMachine<TState, TTrigger>
我想写一个 C++ 等价物。
【问题讨论】:
像这样:
template <typename TState, typename TTrigger>
class StateMachine
{
//...
};
【讨论】:
This site 对如何制作模板类有很好的解释。示例:
// 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;
}
将此与this previous Stack Overflow question 结合使用以实现类的密封方面。
【讨论】: