Re: [Dev-C++] Help with creating objects dynamically
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
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 |