2011-12-20 14 views
6
template <int N> 
class myarray { 
    typedef int Bitmap; 
public: 
    static Bitmap data[N]; 
}; 

template <int N> myarray<N>::Bitmap myarray<N>::data[N]; 

error: expected constructor, destructor, or type conversion before ‘myarray’Bu şablon tanımında yanlış olan nedir? Bir bağımlı tip olduğu için

+2

İlgili: http://stackoverflow.com/questions/610245/where-and-why-do-i- -post-to-the-put-the-put-the-put-the-typename-keywords –

+0

Şimdi aptalca bir takip sorusu için: Neden sadece son satırı silmiyorsunuz? Bu sadece ikinci bir deklarasyon değil mi? –

+2

Doh! Şimdi görüyorum. Tanımsız referanslar. Bu gerekli * tanımıdır *, önceki satır ise sadece * bildirimdir *. –

cevap

9

Sen myarray<N>::Bitmap önce typename gerekir:

template <int N> 
class myarray { 
    typedef int Bitmap; 
public: 
    static Bitmap data[N]; 
}; 

    template <int N> 
    typename myarray<N>::Bitmap myarray<N>::data[N]; 
// ^^^^^^^^ 
İlgili konular