主要使用C#进行编程后,我发现自己在C++方面处于亏损状态.然而,我需要创建一个C++应用程序,因为它只是一个更大的C++解决方案中的一个组件.
情况
问题 - 我不想使用"模板"重新创建可能遇到此数据组件的每个方法和对象...也看到将来可能更改数据类型建议每个进程遇到长对象的模板开始并不理想.
我正在寻找类似于C#Object的东西 - 并编写了以下组件
题
代码
我的Header文件中有以下内容
struct Object
{
Object();
// Return true if value has succesfully been set
// Return false if there is no compatibility between Value and result.
template <typename T>
bool GetValue(T &result);
template<typename T>
bool SetValue(T value);
virtual LPVOID GetObjectAddress() = 0;
virtual const char* GetType() = 0;
};
template<typename T>
struct ObjectType:public Object
{
ObjectType(T value);
T Value; …Run Code Online (Sandbox Code Playgroud)