我有一个通用类Queue
,它包含一个模板Ttype2
作为将存储在每个节点的信息字段中的数据类型的展示位置持有者。 在我的驱动程序类中,我想实例化一个Queue
类对象的数组,但我似乎无法弄清楚。我该如何去做这件事?通用类对象数组C++
这些没有工作,但说明了什么,我试图完成:
// Queue Complex[] = new Queue();//invalid use of template name without identifier list
//Queue<Ttype2> Complex[]; //template arg 1 is invalid
// vector<Queue> Complex2[];//invalid template arguments`
Queue.h水箱内队列类声明和构造函数:
template <typename Ttype2>
class Queue
{
// Global Data Items
protected:
Node <Ttype2> Front, Rear;
int Length;
// member function prototypes
public:
Queue();
void AddRear(Node <Ttype2> ThisNode);
Node <Ttype2> RemoveFront();
void Modify(int Position, Node <Ttype2> ThisNode);
void ClearAll();
int GetSize();`
Node <Ttype2> GetNode(int Position);
Node <Ttype2>* toArray();
};`
// Constructor
template <typename Ttype2>
Queue <Ttype2> :: Queue()
{
Rear = Front = NULL;
Length = 0;
} // End of Constructor
`
我是否需要实现一个通用数组类来容纳这些通用对象? – user3412695