模板错误:非类型“.. [具有T = T]不是类型名称” [英] template error: nontype ".. [with T=T] is not a type name"
本文介绍了模板错误:非类型“.. [具有T = T]不是类型名称”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试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:nontypesfo_type< T> :: aptr32 [with T = T]不是类型名称
sfo_type< T> :: aptr32 m_data;
^
任何人都可以建议这里有什么问题?
<
取决于 T
所以: c> / p>
template< typename T>
class tsfo_vector {
private:
typename sfo_type< T> :: aptr32 m_data;
// ^^^^^^^^
有关使用 typename
请参阅在哪里和为什么我必须把模板和类型名称
Trying to typedef my memory alignment I came out with the following construct (which still is a bit of work in progress because I need to correct the GNU version):
#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
and then I try to use it like this:
template<typename T>
class tsfo_vector {
private:
sfo_type<T>::aptr32 m_data;
int m_size;
...
but then I get the following error message:
/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;
^
Can anyone advice what's wrong here?
解决方案 aptr32
is dependent on T
so:
template<typename T>
class tsfo_vector {
private:
typename sfo_type<T>::aptr32 m_data;
//^^^^^^^^
For further explanation on the use of typename
see Where and why do I have to put the "template" and "typename" keywords?
这篇关于模板错误:非类型“.. [具有T = T]不是类型名称”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文