Note that there are some explanatory texts on larger screens.

plurals
  1. POCreation of a new template container type in c++
    primarykey
    data
    text
    <p>Ok, so I am trying to implement a templated circular doubly linked list in c++. The problem I am running into is that when I try to separate the class definition and the functions into .h and .cpp files respectively, the complier keeps spitting out errors at me about not having the template parameters.</p> <p>Here is the header file, cdl_list.h</p> <pre><code>#ifndef CDL_LIST_H #define CDL_LIST_H #include &lt;iostream&gt; using namespace std; template &lt;typename T&gt; class cdl_list { public: cdl_list(){ first = last = current = NULL;}; // constructor, "current" = "null" ~cdl_list(); // deconstructor void insertFromFront (T &amp;); // inserts an element of type T in the front properly void insertFromBack (T &amp;); // inserts an element of type T in the back properly void deleteFront(); // removes the first element in the list, updating relevant pointers void deleteBack(); // removes the last element in the list, updating relevant pointers void reset(); // makes the "current" pointer the front element void next(); // makes the "current" pointer the next node neighbor T currentValue(); // return the data in the node that "current" refers to void deleteCurrent(); // delete the node that the current pointer refers to; current = old -&gt; next bool isEmpty(); // returns true if and only if the list is empty void print(); // displays the current data in the linked list private: struct listNode* first; struct listNode* last; struct listNode* current; protected: struct listNode { listNode* prev; // "previous" pointer T data; // data in the node listNode* next; // "next" pointer }; }; #include "cdl_list.h" #include &lt;iostream&gt; using namespace std; //And here is the .cpp file, what I have so far, because I can't even get just this one function to compile template &lt; typename T &gt; void cdl_list::insertFromFront(const T &amp;frontInsert) { listNode *oldFirst; oldFirst = (listNode *) malloc(sizeof(listNode)); oldFirst = first; oldFirst -&gt; prev = frontInsert; while(current -&gt; next != first) current = current -&gt; next; frontInsert -&gt; prev = current; current -&gt; next = frontInsert; first = frontInsert; } #endif </code></pre>
    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