2010-11-19 21 views
4

Sınıf tanımı:Templated sınıf yöntem tanımı sözdizimi

template<class K, class V, 
     unsigned hashFunc(const K&), 
     int compFunc(const K&,const K&)=&_compFunc<K> > class X {}; 

Sınıf kod bloğunun dışında bir metot tanımlayabiliriz istiyoruz. gibi pek: derleyici şikayet ediyor Neden

template<class K, class V, 
     unsigned hashFunc(const K&), 
     int compFunc(const K&,const K&)=&_compFunc<K> > 
X<K, V, hashFunc, compFunc>::X() { } 

gr ++ v.4.4.3

error: default argument for template parameter for class enclosing ‘X::X()’

döndürür ve ben işe nasıl yapabilir?

John Dibling işaret ettiği gibi
template<class K, class V, 
     unsigned hashFunc(const K&), 
     int compFunc(const K&,const K&)> 
X<K, V, hashFunc, compFunc>::X() { /* ... */ } 

, sınıf X besbelli de yapıcı ilan etmeli, ama kod netlik için çıkarıldı kabul:

cevap

5

X için bir kurucu bildirmediniz veya tanımlamamışsınız. Ayrıca, X :: X tanımlı denemenizde varsayılan şablon parametrelerini tekrar etmiştiniz. İşte

sabit kod, main -ified:

template<class K, class V, 
     unsigned hashFunc(const K&), 
     int compFunc(const K&,const K&)=&_compFunc<K> > 
class X 
{ 
    X(); 
}; 

template<class K, class V, 
     unsigned hashFunc(const K&), 
     int compFunc(const K&,const K&) > 
X<K, V, hashFunc, compFunc>::X() { } 

int main() 
{ 
} 
4

Varsayılan şablon parametresi tekrar edilmemelidir.

İlgili konular