简体   繁体   中英

template parameters for free functions

I'm experimenting with template template parameters. I have no problems to make them work with classes but for some reason it does not work with 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

I don't understand why the test2 does not compile. It just says: error: expected a class template, got 'freeFunc'

What am I doing wrong?

[edit] what I'm looking for is a way to get a generic way to both get free functions and class template templatized on an enum class

Note that function templates can't be used as template template argument ,

A template argument for a template template parameter must be an id-expression which names a class template or a template alias.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM