2013-02-26 36 views
1

我嘗試以下測試模板的代碼,但我收到以下錯誤:與嵌套模板類的一個問題

error: ‘Foo’ is not a template 

是我的代碼如下正確的嗎?它看起來是我可能做的最簡單的模板代碼!

template<typename D> 
    struct Ciccio{ 
    }; 

    template<typename S> 
    struct Foo< Ciccio<S> >{ 
    }; 


int main(){ 
    typedef Ciccio<int> test_type; 
    Foo<test_type> f; 
    return 1;  
} 

回答

3

就目前而言,Foo看起來像是部分模板專業化。您需要提供一個主要的Foo類模板:

template<typename D> 
struct Ciccio {}; 

// primary template 
template<typename S> 
struct Foo; 

// partial specialization 
template<typename S> 
struct Foo< Ciccio<S> > {}; 

int main(){ 
    typedef Ciccio<int> test_type; 
    Foo<test_type> f; 
} 
+0

HI juanchopanza!這個解釋有效!非常感謝!問候 – 2013-02-26 13:41:12