2013-10-16 60 views
0

我是新來的模板,並找不到我在這裏的論壇上的問題的答案,也許我只是不知道要準確搜索什麼。C++ template預期的主要表達式

我的代碼:

template<class T> 
vector<T> properDivisors(T input) { 
    vector<T>retVal; 
    for(T d = T()+1;d<input;d++) { 
     if((double)input/(double)d == input/d) 
      retVal.push_back(d); 
    } 
    return retVal; 
} 

template<class T> 
T sumTypeOf(T input) { 
    vector<T>divisors = properDivisors(T); 
    return someEnum; 
} 

當編譯我上線得到一個錯誤:

vector<T>divisors = properDivisors(T); 

的錯誤是: 錯誤:前預期主表達式 ')' 令牌

回答

2

您需要傳遞一個值,而不是一個類型:

​​
+0

對不起,這樣可怕的問題,我幾乎馬上想通了 – Parad0x13

0

哈!對不起大家,問題是,我應該寫properDivisors(輸入)

愚蠢的錯誤結點...對不起...