我试图使用typedef来定义我的内存对齐方式,于是我得到了以下的结构(这仍然需要一些进展,因为我需要纠正GNU版本):
#if defined(__GNUG__)
template <typename T>
struct sfo_type {
typedef T* restrict __attribute__((aligned(32))) aptr32;
};
#elif defined(__INTEL_COMPILER)
template <typename T>
struct sfo_type {
typedef T* restrict __attribute__((aligned(32))) aptr32;
};
#endif
然后我尝试像这样使用它:
template<typename T>
class tsfo_vector {
private:
sfo_type<T>::aptr32 m_data;
int m_size;
...
但是我收到了以下错误消息:
/Users/bravegag/code/fastcode_project/code/src/sfo_vector.h(43): error: nontype "sfo_type<T>::aptr32 [with T=T]" is not a type name
sfo_type<T>::aptr32 m_data;
^
有人能指导一下这里出了什么问题吗?
typename
的用法。 - hmjdsfo_type
的定义,但在使用它的时候可能会有一个显式的特化(比如sfo_type<int>
);没有要求特化具有与一般模板相同的成员,因此您必须告诉编译器“这个名称必须是类型名称”。这就是typename
的作用。 - Pete Becker