【问题标题】:error: too few template-parameter-lists错误:模板参数列表太少
【发布时间】:2013-11-01 00:27:19
【问题描述】:

使用 gnu 编译器,我得到了多个错误

error: too few template-parameter-lists

这让我很困惑,因为英特尔编译器似乎在没有警告的情况下处理以下代码段:

// Template to retrieve traits of any MPI object
template <class T>
struct mpi_type_traits {
   typedef T element_type;
   typedef T* element_addr_type;
   static inline MPI_Datatype get_type(T&& val);
   static inline size_t get_size(T& val);
   static inline void* get_addr(T& val);
};

// Specialization of mpi_type_traits for primitive types
#define PRIMITIVE(Type, MpiType) \
        template<> \
        inline MPI_Datatype mpi_type_traits<Type>::get_type(Type&&) { return MpiType; } \
        inline size_t mpi_type_traits<Type>::get_size(Type&) { return 1; } \
        inline void* mpi_type_traits<Type>::get_addr(Type& val) { return &val; }
  PRIMITIVE(char, MPI::CHAR);
  PRIMITIVE(wchar_t, MPI::WCHAR);
  PRIMITIVE(short, MPI::SHORT);
  PRIMITIVE(int, MPI::INT);
  PRIMITIVE(long, MPI::LONG);
  PRIMITIVE(signed char, MPI::SIGNED_CHAR);
  PRIMITIVE(unsigned char, MPI::UNSIGNED_CHAR);
  PRIMITIVE(unsigned short, MPI::UNSIGNED_SHORT);
  PRIMITIVE(unsigned int, MPI::UNSIGNED);
  PRIMITIVE(unsigned long, MPI::UNSIGNED_LONG);
  PRIMITIVE(unsigned long long, MPI::UNSIGNED_LONG_LONG);
  PRIMITIVE(bool, MPI::BOOL);
  PRIMITIVE(std::complex<float>, MPI::COMPLEX);
  PRIMITIVE(std::complex<double>, MPI::DOUBLE_COMPLEX);
  PRIMITIVE(std::complex<long double>, MPI::LONG_DOUBLE_COMPLEX);

#undef PRIMITIVE

通过阅读,这与类型名称规范有关,但我无法确定它需要放置在哪里。很明显,错误是由每个 PRIMITIVE 引起的。

【问题讨论】:

    标签: c++ templates compiler-errors gnu


    【解决方案1】:

    好的,想通了。需要在每个定义的内联之前放置模板。

    ...
    #define PRIMITIVE(Type, MpiType) \
        template<> \
        inline MPI_Datatype mpi_type_traits<Type>::get_type(Type&&) { return MpiType; } \
        template<> \
        inline size_t mpi_type_traits<Type>::get_size(Type&) { return 1; } \
        template<> \
        inline void* mpi_type_traits<Type>::get_addr(Type& val) { return &val; }
      PRIMITIVE(char, MPI::CHAR);
    ...
    

    【讨论】:

      猜你喜欢
      • 2013-11-21
      • 1970-01-01
      • 1970-01-01
      • 2019-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多