Template specialization based on inherit class

后端 未结 4 1918
忘掉有多难
忘掉有多难 2020-12-01 03:39

I want to make this specialized w/o changing main. Is it possible to specialize something based on its base class? I hope so.

-edit-

I\'ll have several class

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-01 04:25

    And the short version now, 2014, using C++-11:

    #include 
    
    struct SomeTag { };
    struct InheritSomeTag : SomeTag { };
    
    template::value>
    struct MyClass { };
    
    template
    struct MyClass {
        typedef int isSpecialized;
    };
    
    int main() {
        MyClass::isSpecialized test1;        /* ok */
        MyClass::isSpecialized test2; /* ok */
    }
    

提交回复
热议问题