converting String to a type name

S

saurabh.rbl

Hello Friends,

The problem is that i get the names of the object type dynamically at
the run time as a string name to a function. Now this function is
suppose to create an object of the type name specified as the string
to the function. (Suppose we already have a class declared by that
name specified)

For e.g.

class ABC
{
};


int main() {
string k = "ABC" ;

// k * a = new k ; how to implement this??

return 0;
}

Thanks a lot,
Saurabh.
 
I

Ian Collins

Hello Friends,

The problem is that i get the names of the object type dynamically at
the run time as a string name to a function. Now this function is
suppose to create an object of the type name specified as the string
to the function. (Suppose we already have a class declared by that
name specified)

For e.g.

class ABC
{
};


int main() {
string k = "ABC" ;

// k * a = new k ; how to implement this??

return 0;
}
Use a std::map of std::string and a helper object that creates the
objects for each name. This assumes the types have a common base.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,197
Latest member
ScottChare

Latest Threads

Top