Reputation: 125
I'm trying to convert one of my files into a template but the typedef statement is giving me some trouble. The error I'm getting is:
error: declaration of ‘typedef typename LinkedList<value_type>::value_type Queue<value_type>::value_type’ shadows template parameter
I'm confused about how to use typedef in this situation because if I 'un-template' the file it considers value_type undefined for the other classes referenced in this file.
My code:
#include <cstdlib>
#include "LinkedList.h"
#include "Node.h"
template <typename value_type>
class Queue
{
public:
typedef typename LinkedList<value_type>::value_type value_type;
Queue();
void enqueue(const value_type& obj);
value_type dequeue();
value_type& front();
bool is_empty() const;
int size() const;
private:
LinkedList<value_type> data;
int used;
};
Upvotes: 1
Views: 75
Reputation: 22023
Your issue is that value_type
is already a known type, it's your template parameter.
You can't have anything else redefining it, especially to a different type.
I had the same "issue" because I wanted another class to retrieve the type used for the template like you did, in that case, rename the template argument to something else.
Upvotes: 5