c++ - 错误 : too few template-parameter-lists

标签 c++ templates compiler-errors gnu

使用 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 引起的。

最佳答案

好的,明白了。需要在每个定义的内联之前放置模板<>。

...
#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);
...

关于c++ - 错误 : too few template-parameter-lists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19718949/

相关文章:

C++函数模板: can't match the best function

c++ - 将元素添加到已排序的链表

c++ - 为 while 循环创建超时的最简洁方法是什么?

c++ - 在其他计算机上运行 Allegro 5

c++ - 在 C++ 容器中一起使用所有子类的设计

c++ - 初学者和 C++ 模板 : Is it an how possible using C++ template make a class oriented to work with chars work with costume structures?

macos - AudioFileReadPackets错误-50

Perl 错误 : Global symbol requires explicit package name

templates - Antlr中StringTemplate的使用

macos - .completePathIntoString 中的编译器错误