how to convert const char* to class

I want a string “MyClass” to be a Class name, and then use it like this: MyClass *obj = new MyClass();
How to do it in cocos2dx? Thanks.

I think that can’t be done with c++ (nothing to do with cocos2dx)

Jesus Bosch wrote:

I think that can’t be done with c++ (nothing to do with cocos2dx)
That’s bad. I remember CShape and JS can do that.Something named reflection.

You could create a class that does this, as long as it has a list of all the possible classes you could make…
Ive seen some tools do this and call it a “factory”

if you wanted it to make a subclass of ccobeject, you could do something LIKE:

CCObject* makeclass(const char* name)
{
if(name “myBox”){
return myBox::Create();
}else if( name "myCircle){
return myCircle::Create();
}
}

There might be a better way of doing it.

daniel fountain wrote:

You could create a class that does this, as long as it has a list of all the possible classes you could make…

Thanks. Considering that I have a large number of classes, I need to complete ‘reflection’ with C++ first.

It’s only a could of lines per class,
I dont know what you mean by “completing” reflection.
This isnt possible with c++, i too looked for a similar method after coming from actionscript and flash