Представление экземпляра Data в виде указателя в связанном списке C++. ⇐ C++
Представление экземпляра Data в виде указателя в связанном списке C++.
Suppose we are a vehicle manufacturer, and we have an abstract Part class that looks like the following:
class Part { // notice that that all methods are const methods. public: Part():itsPartNumber(1) {} Part(int PartNumber):itsPartNumber(PartNumber) {} virtual ~Part() {}; int GetPartNumber() const { return itsPartNumber; } virtual void Display() const = 0; private: int itsPartNumber; }; This will be our Data class in the linked list where the node looks like this.
class PartNode { public: PartNode(Part*); ~PartNode(); void setNext(PartNode* node) { itsNext = node; } Part* GetPart() const; PartNode* GetNext() const; private: Part* itsPart; PartNode* itsNext; }; Now my question is, we can't really manipulate Part instances as all the methods are const. Therefore, does it matter if we change all Part* to just Part? Or should the data itself be a pointer in the linked list?
P.S: I don't think this is a duplicate of Variable as pointer as it was talking about next which of course, has to be a pointer.
Any explanation would be very much appreciated.
Источник: https://stackoverflow.com/questions/780 ... inked-list
Suppose we are a vehicle manufacturer, and we have an abstract Part class that looks like the following:
class Part { // notice that that all methods are const methods. public: Part():itsPartNumber(1) {} Part(int PartNumber):itsPartNumber(PartNumber) {} virtual ~Part() {}; int GetPartNumber() const { return itsPartNumber; } virtual void Display() const = 0; private: int itsPartNumber; }; This will be our Data class in the linked list where the node looks like this.
class PartNode { public: PartNode(Part*); ~PartNode(); void setNext(PartNode* node) { itsNext = node; } Part* GetPart() const; PartNode* GetNext() const; private: Part* itsPart; PartNode* itsNext; }; Now my question is, we can't really manipulate Part instances as all the methods are const. Therefore, does it matter if we change all Part* to just Part? Or should the data itself be a pointer in the linked list?
P.S: I don't think this is a duplicate of Variable as pointer as it was talking about next which of course, has to be a pointer.
Any explanation would be very much appreciated.
Источник: https://stackoverflow.com/questions/780 ... inked-list
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Должен ли я использовать атрибуты или просто оставить все в связанном списке? [закрыто]
Anonymous » » в форуме C++ - 0 Ответы
- 55 Просмотры
-
Последнее сообщение Anonymous
-