簡體   English   中英

免費功能的模板參數

[英]template parameters for free functions

我正在嘗試使用模板模板參數。 我沒有問題可以使它們與類一起使用,但是由於某種原因,它與函數不兼容。

enum class MyEnum { A, B, C, D};

  template<class EnumType, template<EnumType> class Fun >
  class MyTest
    {
    }

    template<MyEnum myEnum>
      void freeFunc(int argument)
        {
        LOG_ERROR("  void freeFunc(int argument) default case!!! ");
        }

      template<>
      void freeFunc<MyEnum::A>(int argument); // implemented in cpp

      template<>
      void freeFunc<MyEnum::B>(int argument); // implemented in cpp

      template<>
      void freeFunc<MyEnum::C>(int argument); // implemented in cpp

      template<>
      void freeFunc<MyEnum::D>(int argument); // implemented in cpp


template<MyEnum s>
class Cde
  {
   public:
  };


  MyTest<MyEnum, Cde > test1; // does compile

  MyTest<MyEnum, freeFunc > test2; // does not compile

我不明白為什么test2無法編譯。 它只是說:錯誤:需要一個類模板,得到了'freeFunc'

我究竟做錯了什么?

我正在尋找的是一種獲得通用方法的方法,該方法既可以獲取免費的函數,又可以在枚舉類上模板化類模板

請注意,函數模板不能用作模板模板參數

模板模板參數的模板參數必須是ID表達式,用於命名類模板或模板別名。

暫無
暫無

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

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