我收到这个错误,在我的项目中,我似乎无法弄清楚,错误是
error explicit type is missing('int assumed)
这就是我所拥有的;
发货.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();
};
物理.h
class Physics{
public:
XMFLOAT2 position;
XMFLOAT2 velocity;
};
这很奇怪,因为它告诉我旋转和速度在我的 rotatleft 函数中未定义,但它在构造函数中没有提示。同样的功能也给我错误显式类型丢失('int assumed')。
最佳答案
您的函数返回类型上的 & 符号应该出现在类名之前;即,而不是这个:
float Ship::&rotateLeft(){
...试试这个:
float & Ship::rotateLeft(){
关于c++ - 错误显式类型丢失 ('int assumed' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19991065/