Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to give a name for an object

Reply
Thread Tools

How to give a name for an object

 
 
Jayden Shui
Guest
Posts: n/a
 
      11-14-2011
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
 
Reply With Quote
 
 
 
 
Larry Evans
Guest
Posts: n/a
 
      11-14-2011
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

 
Reply With Quote
 
 
 
 
Jayden Shui
Guest
Posts: n/a
 
      11-14-2011
On Nov 14, 11:03*am, Larry Evans <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
GIVE ME FILM OR GIVE ME DEATH l#vfgsgEg@AO1.com DVD Video 4 07-14-2005 03:10 PM
Give us 3 minutes; we give you the whole library lib Computer Support 1 02-04-2005 03:16 AM
Give us 3 minutes; we give you the whole library lib Computer Support 0 01-27-2005 07:52 AM
Re: Urgent! how to get object name, method name and attribute name based on the strings? ding feng C++ 2 06-25-2003 01:18 PM



Advertisments