【发布时间】:2017-09-19 03:50:57
【问题描述】:
我有一个通用类Queue,其中包含一个模板Ttype2,作为将存储在每个节点的信息字段中的数据类型的放置持有者。
在我的驱动程序类中,我想实例化一个 Queue 类对象数组,但我似乎无法弄清楚。我该怎么做呢?
这些没有用,但说明了我想要完成的工作:
// 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
`
【问题讨论】:
-
我需要实现一个泛型数组类来保存这些泛型对象吗?
标签: c++ arrays object generics queue