2013-07-29 63 views
0

我试图为cl_float4创建覆盖。OpenCL cl_float4运算符覆盖

定义:

cl_float4 operator- (const cl_float4 &V1, const cl_float4 &V2); 

实现:

cl_float4 operator- (cl_float4 &V1, cl_float4 &V2){ 
    return {V1.x - V2.x, V1.y - V2.y, V1.z - V2.z, V1.w - V2.w}; 
} 

现在,当我做这样的事情:

cl_float4 a = {1,2,3,4}, b = {4,3,2,1}; 

cl_float4 c = a - b; 

这一切工作正常,但:

cl_float4 A = {1,2,3,4},b = {4,3,2,1};

cl_float4 c = a - b - b;

给出了一个错误: “无效的操作数为二进制表达式(cl_float4和cl_float4)”

+0

难道你没有像x,y,z,w这样的东西不是cl_float4的成员吗? – CaptainObvious

+0

我刚刚复制粘贴你的代码,我有这个错误。当我用s [0],s [1],etx代替x,y,z,w时,它对两种情况都很好。 – CaptainObvious

+0

用s [0] -s [3]改变了x,y,z,w。仍然是同样的事情。 – user1513100

回答

0

您需要定义从改变:

cl_float4 operator- (cl_float4 &V1, cl_float4 &V2){ 

cl_float4 operator- (**const** cl_float4 &V1, **const** cl_float4 &V2){ 

的原因是第一次操作(中间/临时​​)的返回值不能隐式转换为cl_float4 &,但它可以隐式转换为const cl_float4 &