错误显式类型缺失(假定为整数)

error explicit type is missing('int assumed')

本文关键字:整数 类型 错误      更新时间:2023-10-16

>我在我的项目中收到此错误,但我似乎无法弄清楚,错误是

缺少错误显式类型(假定为 int)

这就是我所拥有的;

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

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

这很奇怪,因为它告诉我在我的 rotateleft 函数中未定义腐烂和速度,但它在构造函数中没有抱怨。相同的函数也给了我错误显式类型丢失('int 假设')。

函数返回类型上的 & 符号应该在类名之前;即代替这个:

float Ship::&rotateLeft(){

。试试这个:

float & Ship::rotateLeft(){