By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,907 Members | 1,283 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,907 IT Pros & Developers. It's quick & easy.

converting String to a type name

P: n/a
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.

May 28 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
sa*********@gmail.com wrote:
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.

--
Ian Collins.
May 28 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.