代码如下
#include <iostream>
#include "ArrayQueue.h"
#include "LoopQueue.h"
using namespace std;
template<typename E>
void try_ArrayQueue(){
……
}
void try_LoopQueue(){
……
}
double testQueue(E *queue, int opCount){ //未定义标识符 "E"
clock_t startTime = clock();
srand(66);
for(int i=0; i < opCount; i++){
queue->enqueue(rand());
}
for(int i=0;i<opCount;i++){
queue->dequeue();
}
clock_t endTime = clock();
return double(endTime - startTime) / CLOCKS_PER_SEC;
}
int main(){
……
return 0;
}
报错
![](https://img-blog.csdnimg.cn/b64373a2d2ad4a46a901302a0649ed79.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAcmFubnJhbm4=,size_14,color_FFFFFF,t_70,g_se,x_16)
解决方法
将template<typename E>移到testQueue函数上方即可
![](https://img-blog.csdnimg.cn/c579b24137174979be3cc26afea494da.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAcmFubnJhbm4=,size_11,color_FFFFFF,t_70,g_se,x_16)