![]() |
How to give a name for an object
Hello All,
I have a system with a number of classes developed well. Now I want to add a name attribute to classes for input data. It gives each object a name for identification, which provide users convenience in input. The names will not affect the operation of the system. I don't want change existing code a lot. I am thinking using template such as template<class T> class Named : public T { public; // Get or Set name method. private: string mName; }; But if class B is derived from A, Named<B> is not derived from Named<A>. This may give some problems. Any good way to do it? I appreciate your kind help. Best regards, Jayden |
Re: How to give a name for an object
On 11/14/11 09:24, Jayden Shui wrote:
> Hello All, > > I have a system with a number of classes developed well. Now I want to > add a name attribute to classes for input data. It gives each object a > name for identification, which provide users convenience in input. The > names will not affect the operation of the system. I don't want change > existing code a lot. I am thinking using template such as > > template<class T> > class Named : public T > { > public; > // Get or Set name method. > > private: > string mName; > }; > > But if class B is derived from A, Named<B> is not derived from > Named<A>. This may give some problems. > > Any good way to do it? I appreciate your kind help. > > Best regards, > > Jayden I've not use boost serialization, but I remember briefly reading the docs or code and it seems they "register" a class and I think the user has to provide some sort of input/output routines. You might try something similar where your registration would simply provide a map from class name to input/output method. Then, when you read the class name, you dispatch to the input routine retrieved from the map to read the input into the named class. Maybe the boost users list would provide a more detailed and accurate description of how it's done, and you might get some ideas from that. -regards, Larry |
Re: How to give a name for an object
On Nov 14, 11:03*am, Larry Evans <cppljev...@suddenlink.net> wrote:
> On 11/14/11 09:24, Jayden Shui wrote: > > > > > > > > > Hello All, > > > I have a system with a number of classes developed well. Now I want to > > add a name attribute to classes for input data. It gives each object a > > name for identification, which provide users convenience in input. The > > names will not affect the operation of the system. I don't want change > > existing code a lot. I am thinking using template such as > > > template<class T> > > class Named : public T > > { > > public; > > * *// Get or Set name method. > > > private: > > * *string mName; > > }; > > > But if class B is derived from A, Named<B> is not derived from > > Named<A>. This may give some problems. > > > Any good way to do it? I appreciate your kind help. > > > Best regards, > > > Jayden > > I've not use boost serialization, > but I remember briefly reading the docs or code and it seems > they "register" a class and I think the user has to provide > some sort of input/output routines. *You might try something > similar where your registration would simply provide a map > from class name to input/output method. *Then, when you read > the class name, you dispatch to the input routine retrieved > from the map to read the input into the named class. > > Maybe the boost users list would provide a more detailed and > accurate description of how it's done, and you might get > some ideas from that. > > -regards, > Larry Wow! I learned a lot from you!!! Best regards, Jayden |
| All times are GMT. The time now is 09:39 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.