使用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
从阅读开始,这与typename规范有关,但我无法确定它需要放置的位置。很明显,每个PRIMITIVE都会产生错误。
答案 0 :(得分:2)
好的想通了。需要放置模板&lt;&gt;在每个内联定义之前。
...
#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);
...