How to give a name for an object

J

Jayden Shui

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
 
L

Larry Evans

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
 
J

Jayden Shui

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top