Makenshi
Makenshi

Reputation: 1053

Casting problem cant convert from void to float C++

as i said i get this 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 >.<

Upvotes: 1

Views: 692

Answers (3)

sth
sth

Reputation: 229593

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.

Upvotes: 0

Brian R. Bondy
Brian R. Bondy

Reputation: 347216

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.

Upvotes: 0

WhirlWind
WhirlWind

Reputation: 14112

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;
}

Upvotes: 2

Related Questions