Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   How to give a name for an object (http://www.velocityreviews.com/forums/t805901-how-to-give-a-name-for-an-object.html)

Jayden Shui 11-14-2011 03:24 PM

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

Larry Evans 11-14-2011 04:03 PM

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


Jayden Shui 11-14-2011 04:17 PM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57