Creating an instance of an unknown object using a classname string

Hi,

Is it acually possible to get a new instance of a class with just a string name i.e. that is the name of the class ? I know I could use an object factory pattern to do this. Ofcourse this also means that I would have to inherit from every class from a base class - but does a method like this already exists in C++ ?

Thanks

Comments

  • [b][red]This message was edited by stober at 2006-4-30 5:44:25[/red][/b][hr]
    : Hi,
    :
    : Is it acually possible to get a new instance of a class with just a string name i.e. that is the name of the class ? I know I could use an object factory pattern to do this. Ofcourse this also means that I would have to inherit from every class from a base class - but does a method like this already exists in C++ ?
    :
    : Thanks
    :
    :

    I have a c++ program that can print one of 20+ different reports, each report is a c++ class whose base class is CReport. Pass the report function a std::string report name, the function uses a series of if statements and creates an instance of the class, then prints the report through that instance pointer. Microsoft MFC has another method using RUNTIME_CLASS, but I doubt that would be something you would want to emulate.







Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion