显式专注于非命名空间范围错误...急需帮助 [英] Explicit specialization in non-namespace scope error... Desperately need help
问题描述
有人可以帮我将以下代码移植到 GCC 中吗?我在这个网站上发现了很多或相关的问题,但我似乎无法应用在我的案例中建议的解决方法......
typedef float MyData __attribute__((__vector_size__(16)));
模板< typename T> class Data_T
{
public:
template< typename U> static bool IsEqual(const T& a,const T& b)
{
return a == b;
}
//修正:模板<>静态布尔IsEqual< MyData> (const MyData& a,const MyData& b)
static bool IsEqual(const MyData& a,const MyData& b)
{
return true;
$ TriggerProblem(const T& val)
{
if(!IsEqual(1.0f,val))//错误:调用'Data_T< float> :: IsEqual(float,const float&)'
{
}
}
};
触发问题的代码:
Data_T<迈德特>研究所;
inst.TriggerProblem(1.0f);
我得到一个错误错误:非命名空间范围'class Data_T' ,这是由专门化函数 IsEqual()引起的,但现在遇到了另一种类型的错误(没有用于调用'Data_T :: IsEqual(float,const float& )'),这似乎是由我无法删除的 __ vector_size __ 属性造成的。请帮助...
在这种情况下,重载应该足以代替专门化:
模板< typename T> class Data_T
{
public:
template< typename U> static bool IsEqual(const U& a,const U& b)
{
return a == b;
static bool IsEqual(const MyData& a,const MyData& b)
{
return MyDataTypeIsEqual(a,b);
}
模板< typename U> bool IsRangeEqual(const U& a,const U& b,const U& delta)
{
return(a> = b)? (a-b≤Δ):(b-a≤Δ);
bool IsRangeEqual(const MyData& a,常量MyData& b,常量MyData&准确度)
{
return MyDataTypeIsRangeEqual(a,b,准确性);
}
};
编辑关于更新:
从 float
到 float __vector __
的转换已失败,您似乎有一个错字:
模板< typename U> static bool IsEqual(const T& a,const T& b)
vs .:
模板< typename U> static bool IsEqual(const U& a,const U& b)
我相应地修正了上面的代码。
Can somebody please help me to port the following code to GCC? I have found a lot or related questions on this site, but I just can't seem to apply suggested workarounds in my case...
typedef float MyData __attribute__ ((__vector_size__ (16)));
template <typename T> class Data_T
{
public:
template < typename U > static bool IsEqual (const T & a, const T & b)
{
return a == b;
}
//Fixed: template <> static bool IsEqual < MyData > ( const MyData & a, const MyData & b)
static bool IsEqual ( const MyData & a, const MyData & b)
{
return true;
}
void TriggerProblem(const T & val)
{
if (!IsEqual(1.0f, val)) // Error: no matching function for call to 'Data_T<float>::IsEqual(float, const float&)'
{
}
}
};
The code to trigger the problem:
Data_T<MyData> inst;
inst.TriggerProblem(1.0f);
I was getting an error error: explicit specialization in non-namespace scope 'class Data_T', which was caused by specialization function IsEqual(), but now encountered another type of error (no matching function for call to 'Data_T::IsEqual(float, const float&)'), which seems to be caused by the __vector_size__ attribute, which I can't remove. Please help...
In this case overloading should suffice instead of specializing:
template <typename T> class Data_T
{
public:
template<typename U> static bool IsEqual(const U& a, const U& b)
{
return a == b;
}
static bool IsEqual(const MyData& a, const MyData& b)
{
return MyDataTypeIsEqual (a, b);
}
template<typename U> bool IsRangeEqual(const U& a, const U& b, const U& delta)
{
return (a >= b) ? (a - b <= delta) : (b - a <= delta);
}
bool IsRangeEqual(const MyData & a, const MyData & b, const MyData & accuracy)
{
return MyDataTypeIsRangeEqual (a, b, accuracy);
}
};
Edit regarding update:
While for me the conversion from float
to float __vector__
already fails, you seem to have a typo of:
template<typename U> static bool IsEqual(const T& a, const T& b)
vs.:
template<typename U> static bool IsEqual(const U& a, const U& b)
I fixed the above code accordingly.
这篇关于显式专注于非命名空间范围错误...急需帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!