Implicitly convert to link

I have:

struct vec { __m128 m128; inline vec(__m128 m128) : m128(m128) { } } 

so now __m128 can implicitly convert to vec , but when I use it, like in:

 void doStuff(vec &v) { *stuff be doing* } doStuff( _mm_set1_ps(1.0f)); //mm_set_ps returns __m128 

I get an error message:

Unable to convert from __m128 to & vec

so what is the problem and how to fix it?

+6
source share
1 answer

doStuff accepts a reference to non-const vec . Non-trailing links cannot bind to rvalues ​​as a result of calling a function.

If you need to change v inside doStuff , then save the result _mm_set1_ps(1.0f) in an intermediate variable, then call with:

 vec v = _mm_set1_ps(1.0f); doStuff(v); 

If you don't need to change v , change doStuff to accept its argument by reference to const:

 void doStuff(const vec &v) { /*stuff doing*/ } 
+13
source

All Articles