>>If I have the class name in a string varibale, how can I instantiate an object of that class?
Your question is not very clear, but my guess would be that you meant
something like :
class Foo
{
public Foo() { }
};
int main()
{
string className = "Foo";
Foo * foo; //not instantiated but waiting in a sense to be created.
if( className == "Foo") //a string variable has the class name FO
foo = new Foo(); //so create a new class of that object
//after foo is done being used with
delete foo;
}
Last edited by firstPerson; Nov 2nd, 2009 at 2:30 pm.
Reputation Points: 840
Solved Threads: 594
Senior Poster
Offline 3,864 posts
since Dec 2008