I'm trying to implement the following code, but I keep getting an error because of typedef
, can someone please help?
template<class T>
struct box{
T data;
box *link;
};
typedef box* boxPtr;
the error is:
Use of class template 'box' requires template arguments
box
is a class template. This means that it needs an argument whenever you instantiate it:
box<int> integerBox;
box<float> floatBox;
// etc
This is required anywhere you try to use a template class such as box
. So a pointer to just a box
doesn't make sense. It needs a type with it. For example:
template <class type>
using boxptr = box<type>*;
This does effectively the same thing as your typedef, but it allows you to specify he underlying template type.
Of course, if you do it this way, you will always need to specify a type when you use the pointer version:
boxptr<int> integerBoxPtr;
boxptr<float> floatBoxPtr;
// etc