Using an enumeration as a template parameter

后端 未结 4 709
情书的邮戳
情书的邮戳 2020-12-13 09:29

I would like to use a template class to provide some common functionality to some child classes that are very similar. The only variation is the enumeration that each uses.

4条回答
  •  一向
    一向 (楼主)
    2020-12-13 10:06

    The syntax goes for value arguments like it is for typename arguments. Basically, you just replace typename with the name of your enum:

    enum Foo { Bar, Frob };
    
    template  struct Boom {};  // primary template
    template <> struct Boom {};  // specialization of whole class
    
    ...
    
    template <> void Boom::somefun() {}  // specialization of single member
    

提交回复
热议问题