electroRF
Member
Hi,
I'm trying to solve the following exercise and looking for an approaching idea.
a computer store needs a mechanism to enable identifying each item in its stock.
i.e. a specific computer will have different ID than other computers and also than other printers / keyboards, etc.
i need to create a class UniqueID that provides the above requirement.
then, I'll create a few classes that represent items, and the classes will use the UniqueID mechanism and get a unique ID.
You have an idea how to design the UniqueID mechanism?
Thank you.
---
I thought of:
1. creating a UniqueID class, that has static long long m_id; which will be initialized to 0.
2. every item's class will have a data member long long m_id;
3. the constructor will perform:
- - - this->m_id = UniqueID::m_id;
- - - UniqueID::m_id++;
But i'm not sure if it's a good approach.
long long supports 2^64 items' IDs, which is a reasonable limit, and will never be exceeded.
I'm trying to solve the following exercise and looking for an approaching idea.
a computer store needs a mechanism to enable identifying each item in its stock.
i.e. a specific computer will have different ID than other computers and also than other printers / keyboards, etc.
i need to create a class UniqueID that provides the above requirement.
then, I'll create a few classes that represent items, and the classes will use the UniqueID mechanism and get a unique ID.
You have an idea how to design the UniqueID mechanism?
Thank you.
---
I thought of:
1. creating a UniqueID class, that has static long long m_id; which will be initialized to 0.
2. every item's class will have a data member long long m_id;
3. the constructor will perform:
- - - this->m_id = UniqueID::m_id;
- - - UniqueID::m_id++;
But i'm not sure if it's a good approach.
long long supports 2^64 items' IDs, which is a reasonable limit, and will never be exceeded.
Last edited: