使用 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/