Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/143.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;创建自定义对象_C++_Class_Parsing_Dynamic_Types - Fatal编程技术网

C++ C++;创建自定义对象

C++ C++;创建自定义对象,c++,class,parsing,dynamic,types,C++,Class,Parsing,Dynamic,Types,我已经为我的3D引擎开发了一个简单的GUI渲染器,它能够 要像这样解析脚本文件,请执行以下操作: GUIButton Nameofelement .pos 10 20 .size 100 50 class MyPersonalElement : public GUIElement { //all the stuff that belongs in here } GUIElement* currentElement = NULL; if(input == "GUIButton") {

我已经为我的3D引擎开发了一个简单的GUI渲染器,它能够 要像这样解析脚本文件,请执行以下操作:

GUIButton Nameofelement
.pos 10 20
.size 100 50
class MyPersonalElement : public GUIElement
{
    //all the stuff that belongs in here
}
GUIElement* currentElement = NULL;

if(input == "GUIButton")
{
    currentElement = new GUIButton();
    //...
}
基本上,它创建一个类型为
GUIButton
的对象,将其命名为
nameofement
,然后应用以
开头的属性

所有GUI元素都是GUIElement类的子类

我的问题是:任何人都应该能够创建自己的GUIElement子类并注册 它们用于脚本解析。大概是这样的:

GUIButton Nameofelement
.pos 10 20
.size 100 50
class MyPersonalElement : public GUIElement
{
    //all the stuff that belongs in here
}
GUIElement* currentElement = NULL;

if(input == "GUIButton")
{
    currentElement = new GUIButton();
    //...
}
这是我不确定是否可能的部分:

GUI->register("GUIPersonal", MyPersonalElement);
以便您可以在GUI脚本中使用它:

GUIPersonal personalObject
.property value
当前对脚本的分析有点像这样:

GUIButton Nameofelement
.pos 10 20
.size 100 50
class MyPersonalElement : public GUIElement
{
    //all the stuff that belongs in here
}
GUIElement* currentElement = NULL;

if(input == "GUIButton")
{
    currentElement = new GUIButton();
    //...
}

解决此问题的最佳方法是什么?

您可以使用Factory设计模式来创建对象:另请注意,您的问题太广泛了!谢谢你@jordsi和@NG!这就是我要找的。