2014-12-22 4 views
1

Visual Studio 2013에서 문제가 발생했습니다. 그 이유는 설명 할 수 없습니다. 컴파일 문제는 아래 그림과 같습니다.
"RigidBody.cpp/h"클래스를 사용하는 "PhysicsEngine.cpp/h"클래스가 있습니다. 내 Character 클래스 헤더에서 RigidBody 클래스를 사용하려고 시도하면 RigidBody 클래스 식별자가 표시되지 않습니다. 나는 "RigidBody.h"파일을 내 파일에 포함 시켰고 심지어 클래스 프로토 타입을 시도했다. "RigidBody.h"헤더 포함을 삭제할 때 충분히 흥미 롭습니다. 더 많은 오류가 발생하여 읽는 것으로 믿을 수 있습니다. 내가 뭘 잘못하고 있니? 여기 헤더 파일이 보이지 않음 다른 헤더 식별자

I가 오류로 수신되는 출력된다 : 여기서 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 

의 코드 여기

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 ';' 

되어 작동하지 않습니다 코드 (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 

문제를 찾을 필요가있는 추가 사항이 있으면 알려주세요. 잠재적으로 불충분 한 정보로 페이지를 오버로드하고 싶지 않습니다. 고맙습니다!

답변

0

나는이 라인에 문제가 식별자를 찾을 실패 있다는 아니라고 생각 :

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

오히려 당신이 C#을 타입 방식으로 불법 초기화를 위해 노력하고 있다고합니다. C++에서와 같은 선언의 일부로 클래스 멤버에 값을 할당 할 수는 없습니다. 생성자 또는 생성자에 첨부 된 초기화 프로그램에서 초기 값을 할당해야합니다.

+0

변경하려고 시도했지만 여전히 동일한 오류가 발생했습니다. 왜 네가 말하는지 이해 하겠니? "RigidBody * pos;"라고 말하도록 헤더를 변경했습니다. 그리고 나서 Character.cpp 생성자에서 "pos = new RigidBody (0, 0, CHAR_W, CHAR_H, 50, 0, 1, 1);"를 넣었습니다. –

+0

글쎄, 포인터 타입으로 바꾸려면 헤더의 forward 선언문 (class RigidBody;)을 사용하고 .cpp 파일에 필요한 헤더를 #include 할 수 있습니다. –

+0

난 그냥 파일을 전처리하고 컴파일러가 실제로보고있는 것 : http://stackoverflow.com/questions/8978997/how-can-i-see-the-output-of-the-visual-c-preprocessor –

관련 문제