Im trying to convert the following header file into a seperate header and .cpp file.
template <class T>
class Rolodex {
public:
/**
* Creates a new empty Rolodex
*/
Rolodex()
{
sentinel_ = new Item;
sentinel_->value_ = T();
sentinel_->next_ = sentinel_;
sentinel_->prev_ = sentinel_;
current_ = sentinel_;
}
~Rolodex()
{
while (current_ != sentinel_) {
delete_current();
}
delete sentinel_;
}
/**
* Returns true if the Rolodex is positioned at the beginning.
*/
bool is_before_first()
{
return current_ == sentinel_;
}
/**
* Returns true if the Rolodex is positioned at the end.
*/
bool is_after_last()
{
return current_ == sentinel_;
}
/**
* Rotates the Rolodex one step forwards.
*/
void rotate_forward()
{
current_ = current_->next_;
}
/**
* Rotates the Rolodex one step backwards.
*/
void rotate_backward()
{
current_ = current_->prev_;
}
/**
* Returns the value of the current card.
*/
const T ¤t_value()
{
return current_->value_;
}
/**
* Inserts a new item after the current position and
* positions the Rolodex at the newly inserted item.
*/
void insert_after_current(const T &value)
{
Item *coming = new Item;
coming->value_ = value;
coming->next_ = current_->next_;
coming->prev_ = current_;
current_->next_->prev_ = coming;
current_->next_ = coming;
current_ = coming;
}
/**
* Inserts a new item before the current position and
* positions the Rolodex at the newly inserted item.
*/
void insert_before_current(const T &value)
{
Item *coming = new Item;
coming->value_ = value;
coming->prev_ = current_->prev_;
coming->next_ = current_;
current_->prev_->next_ = coming;
current_->prev_ = coming;
current_ = coming;
}
/**
* Deletes current item and positions the Rolodex
* at the _following_ item
*/
void delete_current()
{
Item *going = current_;
current_->prev_->next_ = current_->next_;
current_->next_->prev_ = current_->prev_;
if (going->next_ == sentinel_)
current_ = going->prev_;
else
current_ = going->next_;
delete going;
}
private:
struct Item {
T value_;
Item *next_;
Item *prev_;
};
Item *sentinel_;
Item *current_;
};
#endif /* ROLODEX_H_ */
However when i split them apart, if i don't include
template <class T>
in the header file i get an error trying to declare
T value;
but if i do i get multiple errors in the .cpp file saying Rolodex is not a file class or enumeration. Is there a different type I can use to declare my value; and if so how do i go about modifying the code to fit this. Any help is greatly appreciated im super lost
EDIT: Thank you all for your help, my understanding of the C++ classes was lacking and after some research on the similar threads you provided I fixed my issue.