簡體   English   中英

嵌套類模板完全專業化與部分專業化

[英]Nested class template full specialization versus partial specialization

以下代碼給了我編譯錯誤:

錯誤:非命名空間范圍“結構應用”模板中的顯式專業化<>

  ^ 
#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;
}

在另一篇文章中,我讀到問題在於僅僅是完整的模板專業化 ,而有了部分模板專業化,我將能夠解決此問題。 但是,如何更改代碼中的繼承遞歸以實現此目的? 我嘗試過,但是我摔得很厲害...

這是一個XY問題 您只需要向外移動即可。

template < >
struct Apply::Inheritance< >
{

};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM