我收到此错误,在我的项目中,我似乎无法弄明白,错误是
错误显式类型缺失(假定为int)
这就是我所拥有的;
Ship.cpp
Ship::Ship(){
rot = 0;
position.x = SCREEN_WIDTH / 2;
position.y = SCREEN_HEIGHT / 2;
velocity.x = .2;
velocity.y = .2;
radius = 0;
}
float Ship::&rotateLeft(){
if (rot < 0)
rot += 360;
rot-= velocity.x;
return rot;
}
float Ship::&rotateRight(){
if (rot > 360)
rot -= 360;
rot+= velocity.x;
return rot;
}
float Ship::&getRot(){
return rot;
}
Ship.h
#include "Physics.h"
class Ship : public Physics{
private:
float rot;
public:
float radius;
XMFLOAT2 size;
Ship();
float &rotateRight();
float &rotateLeft();
float &getRot();
};
Physics.h
class Physics{
public:
XMFLOAT2 position;
XMFLOAT2 velocity;
};
这很奇怪,因为它告诉我我的rotateleft函数中的rot和velocity是未定义的,但它并没有在构造函数中抱怨。同样的函数也给了我错误显式类型缺失('int assume')。
答案 0 :(得分:1)
函数返回类型上的&符号应该之前类名;即代替:
float Ship::&rotateLeft(){
...试试这个:
float & Ship::rotateLeft(){