2015-11-06 31 views
0

下面的代碼是給我的編譯錯誤:嵌套類模板完全專業化與偏特

error: explicit specialization in non-namespace scope 'struct Apply' template < >

  ^
#include <iostream> 

struct Apply 
{ 
    template < typename ...BaseClasses> 
    struct Inheritance; 

    template < typename FirstBaseClass, typename ...OtherBaseClasses> 
    struct Inheritance< FirstBaseClass, OtherBaseClasses... > : FirstBaseClass 
      , Inheritance<OtherBaseClasses...> 
    { 

    }; 

    template < > 
    struct Inheritance< > 
    { 

    }; 
}; 

struct A{ int a; }; 
struct B{ int b; }; 
struct C{ int c; }; 

struct Example : Apply::Inheritance< A, B, C > 
{ 
    void print() const 
    { 
     std::cout << a << std::endl; 
     std::cout << b << std::endl; 
     std::cout << c << std::endl; 
    } 
}; 

int main() 
{ 
    Example ex; 

    ex.print(); 

    return 0; 
} 

在另一篇文章我讀的問題是隻是完全模板特,和與部分模板專業我將能夠解決這個問題。但是,我怎麼能改變我的代碼中的繼承遞歸來實現呢?我試過了,但我只把它弄壞了......

回答

2

這是一個XY problem。你必須簡單地將它向外移動。

template < > 
struct Apply::Inheritance< > 
{ 

}; 
+0

謝謝!我嘗試了一切,但最簡單的事情! – nyarlathotep108