Query

N

Naren

Hello All,
Does C++ have only have RTTI i.e. only identification?.Is there any way
that objects can be created knowing the name of the class as string during
run-time?

Thanks in advance.

Regards,
Naren
 
P

Patrik Stellmann

Naren said:
Hello All,
Does C++ have only have RTTI i.e. only identification?.
Don't understand your question...
Is there any way
that objects can be created knowing the name of the class as string during
run-time?
You can do somthing like that using a map to get the pointer to a
create-function for a specific string while the string could be the
value of type_info::name(). Unfortunately the value of type_info::name()
is - as far as i know - not specified in the standard but at least all
MS-VC compilers return the full class name (with napespace) here. The
return value of the create function could be either a void* (not
recommended) or a pointer to the base class of all classes you want to
be able to create with this concept...
 
K

Karl Heinz Buchegger

Naren said:
Hello All,
Does C++ have only have RTTI i.e. only identification?.Is there any way
that objects can be created knowing the name of the class as string during
run-time?

Search your literature (or the web) for 'Factory pattern'
 
R

Rolf Magnus

Patrik said:
You can do somthing like that using a map to get the pointer to a
create-function for a specific string while the string could be the
value of type_info::name(). Unfortunately the value of
type_info::name() is - as far as i know - not specified in the
standard

And further, it doesn't even need to be unique.
but at least all MS-VC compilers return the full class name
(with napespace) here.

g++ returns the string that would be used in name mangling if it were
e.g. the type of a funciton parameter.
 

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

Forum statistics

Threads
474,160
Messages
2,570,889
Members
47,421
Latest member
StacyTaver

Latest Threads

Top