Note that there are some explanatory texts on larger screens.

plurals
  1. POmultiple linked lists for different objects in c++
    primarykey
    data
    text
    <p>consider these classes (simplified)</p> <pre><code>class Character { public: char name[20]; char type[20]; int strength; }; class inventoryItem { public: char name[20]; }; class weapon: public inventoryItem { public: int magical resistance; }; class spell: public inventoryItem { public: int magical power; }; </code></pre> <p>i have written a class for a linked list (not allowed to use stl list)</p> <pre><code>class list { public: struct listItem { listItem* objectPointer; listItem* pnext; }*phead; list() { phead=NULL; } bool isEmpty(){ if (!phead) return true; else return false; } void addToBack(listItem *itemtoadd) { listItem *ptemp; listItem *ppast; listItem *pNewItem; pNewItem=new listItem(); pNewItem-&gt;objectPointer=itemtoadd; pNewItem-&gt;pnext=NULL; if (phead==NULL) phead=itemtoadd; else { ptemp=phead; while(ptemp) { ptemp= ptemp-&gt;pnext; } ptemp-&gt;pnext=itemtoadd; } } }; </code></pre> <p>I have cut this down a lot but my question is , is there an easy way to create linked lists for all these using the same list class ? or am I wasting my time ?</p> <p>every time I have tried it cant convert the pointer from type 'weapon' to type 'listitem'<br> I need a list of characters and a list of each weapon or spell for that character<br> I'm still a beginner with OOP and pointers , the program I have now compiles and I have a list of characters working , however the list is not managed by the class its managed within some other functions, I'm hoping there's a way for one class to deal with it all , can anyone help explain it to me ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload