非命名空间范围错误的显式专业化......迫切需要帮助
有人可以帮我将以下代码移植到GCC吗?我在这个网站上发现了很多或相关的问题,但我似乎无法在我的情况下应用建议的解决方法...
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&)'
{
}
}
};
触发问题的代码:
Data_T<MyData> inst;
inst.TriggerProblem(1.0f);
我收到错误错误:显式专门化在非-命名空间范围“class Data_T”,这是由专门化函数 IsEqual() 引起的,但现在遇到了另一种类型的错误(没有匹配的函数用于调用“Data_T::” IsEqual(float, const float&)'),这似乎是由 __vector_size__ 属性引起的,我无法删除该属性。请帮忙...
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,重载就足够了,而不是专门化:
编辑有关更新:
虽然对我来说从
float
到float __vector__
的转换已经失败,但您似乎有一个拼写错误:vs.:
我相应地修复了上面的代码。
In this case overloading should suffice instead of specializing:
Edit regarding update:
While for me the conversion from
float
tofloat __vector__
already fails, you seem to have a typo of:vs.:
I fixed the above code accordingly.