2015-06-04 53 views
0

最近我被困在模板中,我通過在模板虛擬的參數,但是這是行不通的,在這裏給出編譯錯誤是我的代碼..通過虛擬INT INT模板參數

#include <iostream> 
using namespace std; 
template<typename T> 
class A{ 
    private: 
     T b; 
    public: 
     A() 
     { 
      cout<<"1st is executing "<<endl; 
     } 
}; 
template<typename T,int> 
class A{ 
    private: 
     T b; 
    public: 
     A(){ 
      cout<<"2nd is executing "<<endl; 
     } 
}; 
int main(){ 
    A<string> a; 
    A<string,100> b; 
} 

在我的角度來看,這應該能正常運行,但它給重新申報錯誤,我dn't知道爲什麼..... plz幫助THANKS

回答

0

我不能完全肯定,但我認爲它template <typename T = int>

+0

那是由數據類型即int或char替換的默認參數,但在我的情況下它將被c替換如果它是int,那麼它的值就是10 –

相關問題