 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
wow Guest
|
Posted: Fri Feb 27, 2004 5:10 pm Post subject: How to load a class from given class name in a string ? |
|
|
Hi,
Have a problem at hand.....
I have a text file as follows:
AA : class_a
BB : class_b
............
XX : class_x
Now my c++ prg should read this file and create objects of the classes
in the file at runtime, dynamically. Its not conformed that class_a,
class_b,...., class_x are static. I mean the text file can be changed
at any time so class_a may be class_aaa later. Thus i cant use if/
switch in my program.
If u r going to ask about runtime polimorphism or inheriting all
classes with a dummy base class and then use its pointer then it wont
work.
I m talking about functionality that is provided by CRuntimeClass in
MFC, but i have to do the same in c++.
Can anyone help???
So finally, i have a string, have to read the string, take it as
classname and create object of it. All these at runtime.
Thanx in advance...
Pravin.
|
|
| Back to top |
|
 |
Karl Heinz Buchegger Guest
|
Posted: Fri Feb 27, 2004 6:20 pm Post subject: Re: How to load a class from given class name in a string ? |
|
|
wow wrote:
| Quote: |
Hi,
Have a problem at hand.....
I have a text file as follows:
AA : class_a
BB : class_b
...........
XX : class_x
Now my c++ prg should read this file and create objects of the classes
in the file at runtime, dynamically. Its not conformed that class_a,
class_b,...., class_x are static. I mean the text file can be changed
at any time so class_a may be class_aaa later. Thus i cant use if/
switch in my program.
If u r going to ask about runtime polimorphism or inheriting all
classes with a dummy base class and then use its pointer then it wont
work.
I m talking about functionality that is provided by CRuntimeClass in
MFC, but i have to do the same in c++.
Can anyone help???
So finally, i have a string, have to read the string, take it as
classname and create object of it. All these at runtime.
|
In other words: you are looking for the 'factory pattern'
Search the web with this keywords and you should find something.
--
Karl Heinz Buchegger
[email]kbuchegg (AT) gascad (DOT) at[/email]
|
|
| Back to top |
|
 |
ak Guest
|
Posted: Sat Feb 28, 2004 8:23 am Post subject: Re: How to load a class from given class name in a string ? |
|
|
On 27 Feb 2004 09:10:38 -0800,
[email]wowpravin (AT) hotmail (DOT) com[/email] (wow) wrote:
//So finally, i have a string, have to read the string, take it as
//classname and create object of it. All these at runtime.
//
sounds like COM :)
/ak
|
|
| Back to top |
|
 |
Sharad Kala Guest
|
Posted: Sat Feb 28, 2004 8:48 am Post subject: Re: How to load a class from given class name in a string ? |
|
|
"ak com>" <ak@workmail
| Quote: | On 27 Feb 2004 09:10:38 -0800,
[email]wowpravin (AT) hotmail (DOT) com[/email] (wow) wrote:
//So finally, i have a string, have to read the string, take it as
//classname and create object of it. All these at runtime.
//
sounds like COM
|
This is offtopic but I don't think that's correct.
<OT>
IIRC, in COM one does not create objects given a string.
Given a string/ProgId/CLSID one can load the object(dll/exe) and reach an
interface though.
</OT>
-Sharad
|
|
| Back to top |
|
 |
ak Guest
|
Posted: Sun Feb 29, 2004 11:51 am Post subject: Re: How to load a class from given class name in a string ? |
|
|
On Sat, 28 Feb 2004 14:18:40 +0530, "Sharad Kala"
<no.spam_sharadk_ind (AT) yahoo (DOT) com> wrote:
//
//"ak com>" <ak@workmail
//news:lvj0405pugfnh710v6v608cbsrisvo451o (AT) 4ax (DOT) com...
//> On 27 Feb 2004 09:10:38 -0800,
//> [email]wowpravin (AT) hotmail (DOT) com[/email] (wow) wrote:
//>
//> //So finally, i have a string, have to read the string, take it as
//> //classname and create object of it. All these at runtime.
//> //
//>
//> sounds like COM
//
//This is offtopic but I don't think that's correct.
//<OT>
//IIRC, in COM one does not create objects given a string.
//Given a string/ProgId/CLSID one can load the object(dll/exe) and reach an
//interface though.
//</OT>
//-Sharad
//
<OT>
its the factory pattern, COM is one example of
using the factory pattern.
actually yes, the string/progid/clsid/guid are
used to load the dll / exe as well as create the
objects they implement; manipulating the objects
is done via interfaces.
</OT>
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|