C++ to C# porting
C++ to C# porting
如何将这段代码(c ++)移植到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() { }
};
假设这确实是一个纯粹抽象的基类,它看起来像这样:
interface State<T>
{
void Enter(T arg);
void Execute(T arg);
void Exit(T arg);
};
不过,确切的参数传递约定很尴尬。如果不知道你想做什么,就很难确切地说出你应该在 C# 中做什么。可能,void FunctionName(ref T arg)
可能更合适。
一些类似的东西:
interface State<T> : IDisposable
{
void Enter(T t);
void Execute(T t);
void Exit(T t);
}
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);
}
这似乎:D有效
你可以这样写
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();
}
将 T 修复为实体类型类。
相关文章:
- "error: no matching function for call to"构造函数错误
- 调用专用模板时出错"no matching function for call to [...]"
- C++ Singleton - Prevent ::instance() to variable
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- Visual Studio Code "undefined reference to `WinMain@16'"
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 如何解决"invalid conversion from 'char' to 'const char*'"
- 使用 MATLAB 编码器生成C++代码:编译错误"undefined reference to `rgb2gray_tbb_real64'"
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- Python str to C++ to Python str
- 为什么创建友元类的实例会导致"undefined reference to"错误?
- System.InvalidCastException - SQL to C++ - safe_cast<float>
- 使用 cmake 的 Linux 终端上的"Conversion to non-scalar type is requested"错误
- "no matching function for call to 'Vector::Vector'"错误
- vector<vector<double>> to mxArray using memcpy
- Tensorflow c++ api undefined reference to 'tflite::D efaultErrorReporter()'
- 当覆盖存在时调用基本虚拟"binded to object"函数
- OpenGL VBO Indexing ( How to compute Index Array)
- porting std::wstring to gcc cygwin
- C++ to C# porting