Thread: [Dev-C++] Help with creating objects dynamically
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Satish M. <sat...@ya...> - 2003-07-21 04:28:36
|
Hello, I have the following requirement while creating objects.. I will try to explain it using a small example.. Suppose I have a class Student defined and I want to create objects of type Student inside the main function.. And say, the actual name with which i want to create the obect is stored in a character array at run time.. say i have the following statement char NAME[]=getName(); and the above function is returning the name "JOHN" at run time. Now i want to get the name out of the character array and create the object using that particular name at run time.. i.e., Student JOHN; in a nutshell i want to give the name of the objects to be created at run time. IS THIS POSSIBLE?? IF SO CAN ANYONE HELP ME WITH THIS?? Thank You in advance. -Sateesh Medepalli __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com |
|
From: <or...@vp...> - 2003-07-21 10:55:42
|
Satish Medepalli wrote: > I have the following requirement while creating objects.. I will try to > explain it using a small example.. > > Suppose I have a class Student defined and I want to create objects of > type Student inside the main function.. > > And say, the actual name with which i want to create the obect is > stored in a character array at run time.. say i have the following > statement > char NAME[]=getName(); > and the above function is returning the name "JOHN" at run time. > > Now i want to get the name out of the character array and create the > object using that particular name at run time.. i.e., > Student JOHN; > > in a nutshell i want to give the name of the objects to be created at > run time. IS THIS POSSIBLE?? IF SO CAN ANYONE HELP ME WITH THIS?? Nope. As far as I know, this is not possible in C++. I know, that Perl can do it, but if you EVER programmed in Perl, you know how different it is. So I don't think it ca nbe done. A solution to your problem might be to give a "name" member to your class, then at object creation, the constructor takes it as parameter, and copies it into the name member. -- Greetings, Balázs |
|
From: Marc H. <ma...@e-...> - 2003-07-21 17:23:25
|
I can see absolutely no requirement to do this at all. In addition (and = to answer the question) I can see absolutely no way of doing it either. Scripting languages that have some kind of eval statement could do this, = but again, I can see no requirement for it (although I have used a similar mechanism in a JScript ASP project to create objects of a particular = name, but never dependant on data within the object itself).=20 Maybe if you enlighten us on why you would want to do this, we could = help you find a solution. __________________________________ Marc Heiligers =20 -----Original Message----- From: dev...@li... [mailto:dev...@li...] On Behalf Of Satish Medepalli Sent: 21 July 2003 06:28 To: dev...@li... Subject: [Dev-C++] Help with creating objects dynamically Hello, I have the following requirement while creating objects.. I will try = to explain it using a small example.. Suppose I have a class Student defined and I want to create objects = of type Student inside the main function.. And say, the actual name with which i want to create the obect is stored in a character array at run time.. say i have the following statement char NAME[]=3DgetName(); and the above function is returning the name "JOHN" at run time. Now i want to get the name out of the character array and create the object using that particular name at run time.. i.e.,=20 Student JOHN; =20 in a nutshell i want to give the name of the objects to be created at run time. IS THIS POSSIBLE?? IF SO CAN ANYONE HELP ME WITH THIS?? Thank You in advance. -Sateesh Medepalli=20 __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com |
|
From: Satish M. <sat...@ya...> - 2003-07-21 17:36:11
|
Hello Marc, Thank you for your reply. There is no real necessity for me to do so.. I can make it work using a hash table or some kind of a mapping function.. I just thought that if it was possible in the way I earlier asked, I could save some execution time as there will not be much need for searching operation.. As i got almost every feedback saying that this is not possible, I think I will stick to a hash table solution. Thank you for all your help with this. -Sateesh Medepalli --- Marc Heiligers <ma...@e-...> wrote: > I can see absolutely no requirement to do this at all. In addition (and > to > answer the question) I can see absolutely no way of doing it either. > Scripting languages that have some kind of eval statement could do this, > but > again, I can see no requirement for it (although I have used a similar > mechanism in a JScript ASP project to create objects of a particular > name, > but never dependant on data within the object itself). > > Maybe if you enlighten us on why you would want to do this, we could > help > you find a solution. > > __________________________________ > Marc Heiligers > > > > -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf Of Satish > Medepalli > Sent: 21 July 2003 06:28 > To: dev...@li... > Subject: [Dev-C++] Help with creating objects dynamically > > Hello, > > I have the following requirement while creating objects.. I will try > to > explain it using a small example.. > > Suppose I have a class Student defined and I want to create objects > of > type Student inside the main function.. > > And say, the actual name with which i want to create the obect is > stored in a character array at run time.. say i have the following > statement > char NAME[]=getName(); > and the above function is returning the name "JOHN" at run time. > > Now i want to get the name out of the character array and create the > object using that particular name at run time.. i.e., > Student JOHN; > > in a nutshell i want to give the name of the objects to be created at > run time. IS THIS POSSIBLE?? IF SO CAN ANYONE HELP ME WITH THIS?? > > Thank You in advance. > -Sateesh Medepalli > > __________________________________ > Do you Yahoo!? > SBC Yahoo! DSL - Now only $29.95 per month! > http://sbc.yahoo.com > > __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com |
|
From: Marc H. <ma...@e-...> - 2003-07-22 04:35:58
|
Hi Sateesh, I think what you're looking for is the STL std::map which serves as a = kind of associative array. There are other guys on this list more educated in = the ways of STL than I. I'm sure they will help you out if you have = problems.=20 __________________________________ Marc Heiligers -----Original Message----- Hello Marc, Thank you for your reply. There is no real necessity for me to do so.. = I can make it work using a hash table or some kind of a mapping function.. = I just thought that if it was possible in the way I earlier asked, I could save some execution time as there will not be much need for searching operation.. As i got almost every feedback saying that this is not possible, I = think I will stick to a hash table solution. Thank you for all your help with this. -Sateesh Medepalli --- Marc Heiligers <ma...@e-...> wrote: > I can see absolutely no requirement to do this at all. In addition=20 > (and to answer the question) I can see absolutely no way of doing it=20 > either. Scripting languages that have some kind of eval statement=20 > could do this, but > again, I can see no requirement for it (although I have used a similar > mechanism in a JScript ASP project to create objects of a particular > name, > but never dependant on data within the object itself).=20 >=20 > Maybe if you enlighten us on why you would want to do this, we could=20 > help you find a solution. >=20 > __________________________________ > Marc Heiligers >=20 > -----Original Message----- >=20 > I have the following requirement while creating objects.. I will=20 > try to explain it using a small example.. >=20 > Suppose I have a class Student defined and I want to create objects = > of type Student inside the main function.. >=20 > And say, the actual name with which i want to create the obect is=20 > stored in a character array at run time.. say i have the following=20 > statement char NAME[]=3DgetName(); > and the above function is returning the name "JOHN" at run time. >=20 > Now i want to get the name out of the character array and create=20 > the object using that particular name at run time.. i.e., Student=20 > JOHN; >=20 > in a nutshell i want to give the name of the objects to be created=20 > at run time. IS THIS POSSIBLE?? IF SO CAN ANYONE HELP ME WITH THIS?? >=20 > Thank You in advance. > -Sateesh Medepalli |
|
From: Ioannis V. <iv...@em...> - 2003-07-21 20:16:35
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf Of Satish > Medepalli > Sent: 21 July 2003 06:28 > To: dev...@li... > Subject: [Dev-C++] Help with creating objects dynamically > > Hello, > > I have the following requirement while creating objects.. > I will try to > explain it using a small example.. > > Suppose I have a class Student defined and I want to > create objects of > type Student inside the main function.. > > And say, the actual name with which i want to create the obect is > stored in a character array at run time.. say i have the following > statement > char NAME[]=getName(); > and the above function is returning the name "JOHN" at run time. > > Now i want to get the name out of the character array and > create the > object using that particular name at run time.. i.e., > Student JOHN; > > in a nutshell i want to give the name of the objects to be > created at > run time. IS THIS POSSIBLE?? IF SO CAN ANYONE HELP ME WITH THIS?? > > Thank You in advance. > -Sateesh Medepalli Strangely enough I did not receive your email and I am answering it through Marc Heiligers 's email. After the compilation no object has any name. So you can't define its name at run time (and even if they had, how would that be useful to you?) . Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net |
|
From: Abhijit S. <mu...@gm...> - 2003-07-21 17:45:08
|
Hello, Satish.
> I have the following requirement while creating objects.. I will try to
> explain it using a small example..
Well, for one, you have to get it out of your head that the name of the
object changes its behaviour, or, for that matter, your understanding of the
program.
If what you want is to be able to tell who the student is from the object,
simply add a variable to store the name of your student:
class Student
{
// foo.
char *student_name;
};
And create some mutators/accessors/constructors/whatever that work with this
new member.
--
Abhijit Shylanath
Homepage: http://mudeth.tripod.com/
|
|
From: Graham D. <g.d...@nt...> - 2003-07-21 18:11:31
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"> <title></title> </head> <body> <br> <br> Satish Medepalli wrote:<br> <blockquote type="cite" cite="mid...@we..."> <pre wrap="">Hello, I have the following requirement while creating objects.. I will try to explain it using a small example.. Suppose I have a class Student defined and I want to create objects of type Student inside the main function.. And say, the actual name with which i want to create the obect is stored in a character array at run time.. say i have the following statement char NAME[]=getName();</pre> </blockquote> You can't do that, either<br> <blockquote type="cite" cite="mid...@we..."> <pre wrap=""> and the above function is returning the name "JOHN" at run time. Now i want to get the name out of the character array and create the object using that particular name at run time.. i.e., Student JOHN; in a nutshell i want to give the name of the objects to be created at run time. IS THIS POSSIBLE?? IF SO CAN ANYONE HELP ME WITH THIS??</pre> </blockquote> No, it's not and, like others I can't see a need.<br> <blockquote type="cite" cite="mid...@we..."> <pre wrap=""> Thank You in advance. -Sateesh Medepalli __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! <a class="moz-txt-link-freetext" href="http://sbc.yahoo.com">http://sbc.yahoo.com</a> ------------------------------------------------------- This SF.net email is sponsored by: VM Ware With VMware you can run multiple operating systems on a single machine. WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the same time. Free trial click here: <a class="moz-txt-link-freetext" href="http://www.vmware.com/wl/offer/345/0">http://www.vmware.com/wl/offer/345/0</a> _______________________________________________ Dev-cpp-users mailing list <a class="moz-txt-link-abbreviated" href="mailto:Dev...@li...">Dev...@li...</a> TO UNSUBSCRIBE: <a class="moz-txt-link-freetext" href="http://www23.brinkster.com/noicys/devcpp/ub.htm">http://www23.brinkster.com/noicys/devcpp/ub.htm</a> <a class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/dev-cpp-users">https://lists.sourceforge.net/lists/listinfo/dev-cpp-users</a> </pre> </blockquote> </body> </html> |
|
From: Per W. <pw...@ia...> - 2003-07-21 20:47:36
|
Hi Graham! Is there possibly some settings to be made in your mail client, to allow it to better separate your text from the text you are answering? I see that you are using a html client while I - as a lot of other users - are using text clients. As you can see from the attached text, it really is hard to separate your text from Satish's. If nothing else is possible, maybe you may write GD: at the start of each of your lines. I don't want to read the original questions multiple times, just locate the answers and see if I'm satisfied, or if I maybe have some more comments on the issue at hand. /Per W On Mon, 21 Jul 2003, Graham Douglas wrote: > > > Satish Medepalli wrote: > > Hello, > > I have the following requirement while creating objects.. I will try to > explain it using a small example.. > > Suppose I have a class Student defined and I want to create objects of > type Student inside the main function.. > > And say, the actual name with which i want to create the obect is > stored in a character array at run time.. say i have the following > statement > char NAME[]=getName(); > > You can't do that, either > > and the above function is returning the name "JOHN" at run time. > > Now i want to get the name out of the character array and create the > object using that particular name at run time.. i.e., > Student JOHN; > > in a nutshell i want to give the name of the objects to be created at > run time. IS THIS POSSIBLE?? IF SO CAN ANYONE HELP ME WITH THIS?? > > No, it's not and, like others I can't see a need. > > Thank You in advance. > -Sateesh Medepalli > |
|
From: Graham D. <g.d...@nt...> - 2003-07-21 21:58:14
|
Is this any better? I've tried setting the preferences for this mailing list to "plain text" so that it doesn't try to send HTML - let's see if it works. I might have to try a couple of times to get the formatting right, though. Sorry for the confusion - I'll get there in the end. Graham Per Westermark wrote: >Hi Graham! > >Is there possibly some settings to be made in your mail client, to allow >it to better separate your text from the text you are answering? I see >that you are using a html client while I - as a lot of other users - are >using text clients. As you can see from the attached text, it really is >hard to separate your text from Satish's. > >If nothing else is possible, maybe you may write GD: at the start of each >of your lines. I don't want to read the original questions multiple times, >just locate the answers and see if I'm satisfied, or if I maybe have some >more comments on the issue at hand. > >/Per W > >On Mon, 21 Jul 2003, Graham Douglas wrote: > > > >>Satish Medepalli wrote: >> >> Hello, >> >> I have the following requirement while creating objects.. I will try to >>explain it using a small example.. >> >> Suppose I have a class Student defined and I want to create objects of >>type Student inside the main function.. >> >> And say, the actual name with which i want to create the obect is >>stored in a character array at run time.. say i have the following >>statement >>char NAME[]=getName(); >> >>You can't do that, either >> >> and the above function is returning the name "JOHN" at run time. >> >> Now i want to get the name out of the character array and create the >>object using that particular name at run time.. i.e., >>Student JOHN; >> >> in a nutshell i want to give the name of the objects to be created at >>run time. IS THIS POSSIBLE?? IF SO CAN ANYONE HELP ME WITH THIS?? >> >>No, it's not and, like others I can't see a need. >> >> Thank You in advance. >>-Sateesh Medepalli >> >> >> > > > > >------------------------------------------------------- >This SF.net email is sponsored by: VM Ware >With VMware you can run multiple operating systems on a single machine. >WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the >same time. Free trial click here: http://www.vmware.com/wl/offer/345/0 >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > |
|
From: Per W. <pw...@ia...> - 2003-07-21 22:37:26
|
Seems to work find - nice indentation of my original mail :-) /Per W On Mon, 21 Jul 2003, Graham Douglas wrote: > Is this any better? I've tried setting the preferences for this mailing > list to "plain text" so that it doesn't try to send HTML - let's see if > it works. I might have to try a couple of times to get the formatting > right, though. > > Sorry for the confusion - I'll get there in the end. > > Graham |