头文件没有看到其他标头标识符

时间:2014-12-22 21:50:26

标签: c++ visual-studio compiler-errors header include

我一直遇到Visual Studio 2013的问题。我无法解释为什么会发生这种情况。编译问题如下图所示 我有一个类“PhysicsEngine.cpp / h”使用类“RigidBody.cpp / h”就好了。一旦我尝试在我的Character类头中使用RigidBody类,它就无法看到RigidBody类标识符。我在我的文件中包含了“RigidBody.h”,甚至尝试过对该类进行原型设计。有趣的是,当我删除“RigidBody.h”标题包含时,它会吐出更多的错误,让我相信它正在阅读它。有什么我做错了吗?

以下是我收到的错误输出:

1>------ Rebuild All started: Project: SideScroller, Configuration: Debug Win32 ------
1>  WorldChunkManager.cpp
1>  World.cpp
1>  Vector.cpp
1>e:(directory)\vector.cpp(41): warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data
1>e:(directory)\vector.cpp(48): warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data
1>  Tile.cpp
1>  RigidBody.cpp
1>e:(directory)\character.h(21): error C2146: syntax error : missing ';' before identifier 'pos'
1>e:(directory)\character.h(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>e:(directory)\character.h(21): error C2143: syntax error : missing ';' before '='
1>e:(directory)\character.h(21): error C2238: unexpected token(s) preceding ';'

以下是RigidBody.h的代码

#ifndef RH
#define RH

#include "Vector.h"
#include "World.h"
#include <cmath>
#include <list>

class RigidBody
{
    private:
    int id;
    float gravityFactor;
    float airResistFactor;

    float mass;
    float elasticity;

    Vector pos = Vector(0, 0);
    int width;
    int height;

    Vector velocity = Vector(0, 0);

    std::list<Vector>* additiveVelocities;
    std::list<Vector>* forces;
public:
    RigidBody(int x, int y, int w, int h, float mass, float elasticity, float gravityFactor,         float airResistFactor);
    ~RigidBody();

    static int rigidBodyCount;

    //Get/Set
    int getID();
    double getX();
    double getY();
    float getGravFact();
    float getAirFact();
    float getMass();
    float getElast();
    Vector getPos();
    Vector getVelocity();
    std::list<Vector>* getadditiveVelocities();
    std::list<Vector>* getForces();

    void setX(double x);
    void setY(double y);
    void setVelocity(Vector& vec);
    void setPos(Vector& vec);

    //Interactino Functions
    void addForce(Vector force);
    void addVelocity(Vector velocity);
};


#endif

这是不起作用的代码(Character.h):

#ifndef CHARACTER_H
#define CHARACTER_H

#include "SDL.h"
#include "Camera.h"
#include "InputManager.h"
#include "Vector.h"
#include "RigidBody.h"

//TEMP DIM
const int CHAR_H = 64;
const int CHAR_W = 12;

class Character
{
private:
    double speed;

    //Vector pos = Vector(0, 0);

    RigidBody pos = RigidBody(0, 0, CHAR_W, CHAR_H, 50, 0, 1, 1);

    InputManager* inputPtr;
public:
    Character(int x, int y, InputManager* inputPtr);

    void getXY(int* dest);
    void getChXY(int* dest);
    void getCenterXY(int* dest);

    //Update
    void update(long double last);

    bool isFloor();

    //Draw
    void draw(SDL_Surface* screen, Camera* camPtr);
};

#endif

如果您还有其他需要找到问题,请告诉我!我不想用可能不敬的信息重载页面。谢谢!

1 个答案:

答案 0 :(得分:0)

我认为这一行的问题并不在于它找不到标识符:

RigidBody pos = RigidBody(0, 0, CHAR_W, CHAR_H, 50, 0, 1, 1);

相反,它是你尝试以C#方式进行非法初始化。您不能像在C ++中那样将一个值赋给类成员作为其声明的一部分。您需要在构造函数中或在附加到构造函数的初始化程序中分配初始值。