C++ int float casting

后端 未结 8 1572

Why is m always = 0? The x and y members of someClass are integers.

float getSlope(someClass a, someClass b)
{           
    float m = (a.y - b.y) / (a.x -         


        
8条回答
  •  青春惊慌失措
    2020-12-09 08:19

    You are performing calculations on integers and assigning its result to float. So compiler is implicitly converting your integer result into float

提交回复
热议问题