开发者

Casting problem cant convert from void to float C++

开发者 https://www.devze.com 2022-12-30 14:28 出处:网络
as i saidi get t开发者_运维百科his horrible error i dont really know what to do anymore float n= xAxis[i].Normalize();

as i said i get t开发者_运维百科his horrible error i dont really know what to do anymore

 float n= xAxis[i].Normalize();

thats where i get the error and i get it cuz normalize is a void function this is it

void CVector::normalize()
{
 float len=Magnitude();
 this->x /= len;
 this->y /= len;  
}

i need normalize to stay as void tho i tried normal casting like this

float n= (float)xAxis[i].Normalize();

and it doesnt work also with static,dynamic cast,reinterpret,const cast and cant make it work any help would be really apreciated... thank you >.<


A void function doesn't return anything, so there's nothing to assign to n.

You should return some value from normalize to assign it to n.

float CVector::normalize()
{
 float len=Magnitude();
 this->x /= len;
 this->y /= len;
 return 10.0;
}


Normalize doesn't return a value as it has a void return type. It changes an internal member. So you have to access that member directly or an accessor that returns that member.


The Normalize() method doesn't return anything, so you can't assign the return value to a variable. Probably Normalize() just modifies the object it is called on.

0

精彩评论

暂无评论...
验证码 换一张
取 消