2013-02-26 59 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