启动前缺少模板参数

时间:2014-02-17 08:49:32

标签: c++ templates vector linked-list

我想比较一个向量与链表填充的时间

#include <iostream>
#include <sstream>
#include <list>
#include <vector>
#include <ctime>
#include <time.h>

using namespace std;

int main()
{
   list<int> mylist;
   vector<int> myvector;
   srand(time(NULL));
   int num;

   clock_t list_start;
   clock_t list_end;

   list start = clock();

   for (int i = 0 ; i < 10000000 ; i++ ) // 1 billion times
   {    
        num = rand() % 1000000000 ;        
        mylist.push_back(num);
   }

   list end = clock();

   cout << difftime(list_start,list_end);       
   cout <<" List is done ";

   clock_t vector_start;      
   clock_t vector_end;

   for (int i = 0 ; i < 10000000 ; i++ ) // 1 billion times
   {    
        num = rand() % 1000000000 ;       
        myvector.push_back(num);
   }

   cout << difftime(vector_start,vector_end);       
   cout << " Vector is done " ;

}

我收到以下错误

  

启动前缺少模板参数;   预期的在开始之前

如何更正这些错误?

2 个答案:

答案 0 :(得分:2)

更改

list start = clock();

list<int> start = clock();

它将修复错误。 但可能你会写

list_start = clock();

感谢@Retired Ninja

答案 1 :(得分:1)

list start = clock();会为时钟返回一个列表对象。那应该是list_end = clock();