2017-01-26 4 views
-1

私は、ゲームフレームワークに実装するためのBullet物理学のラッパーを作成しようとしています。コンストラクタは適切な定義を見つけることができず、他の100のエラーはどこにもありませんか?

私は3つのクラスを持っています、mDebugDrawは、弾丸のデバッグ描画の実装です。

mRigidBodyは、弾丸の剛体の物のための容器です。

世界は弾丸の世界的なもののための容器です。

ビジュアルスタジオで〜100エラーがあり、ほとんどすべてがmRigidBodiesを作成しようとしている場所から来ています。エラーは「初期化リストからmRigidBodyに変換できません」、「適切なコンストラクタはありません」、 "mRigidBody :: mRigidBody(std :: string)メンバ関数がすでに定義または宣言されている"のような奇妙なものもありますが、これは実装した関数ではありません。

world.hは、これらの3つのクラスの定義が含まれます。エラーの

#pragma once 
#include <btBulletDynamicsCommon.h> 
#include <BulletCollision\CollisionShapes\btBoxShape.h> 
#include <GL/glew.h> 
#include "LinearMath\btIDebugDraw.h" 
#include <vector> 
#include <glm\vec3.hpp> 
#include <iostream> 
#include <map> 

class mDebugDraw : public btIDebugDraw 
{ 
private: 
    int debugMode; 
public: 
    mDebugDraw(); 
    virtual ~mDebugDraw(); 

    struct mLine 
    { 
     glm::vec3 from; 
     glm::vec3 to; 
     glm::vec3 color; 

     mLine(const glm::vec3 ifrom, const glm::vec3 ito, glm::vec3 _color) 
     { 
      from = ifrom; 
      to = ito; 
      color = _color; 

     } 
    }; 

    std::vector<mLine> lines; 

    struct mColor 
    { 
     glm::vec3 col; 

     mColor(const glm::vec3 c) 
     { 
      col = c; 
     } 
    }; 

    std::vector<mColor> colors; 

    GLuint vao; 
    GLuint vbo[2]; 

    virtual void drawLine(const btVector3& from, const btVector3& to, const btVector3& color); 

    virtual void drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color); 

    virtual void draw3dText(const btVector3& location, const char* textString); 

    virtual void setDebugMode(int m_debugMode); 

    virtual int getDebugMode() const; 

    virtual void drawTriangle(const btVector3 & a, const btVector3 & b, const btVector3 & c, const btVector3 & color, btScalar alpha) {} 

    void reportErrorWarning(const char * warningString) { std::cout << "Physics debugger warning: " << warningString << std::endl; } 

    std::vector<mLine> & GetLines() { return lines; } 

    void draw(); 

    void clean(); 
}; 

class mRigidBody 
{ 
public: 
    mRigidBody(std::string name, World::shapeTypes type, glm::vec3 extent, glm::vec3 startposition); 
    mRigidBody(std::string name, World::shapeTypes type, glm::vec3 extent, glm::vec3 startPosition, float mass, float friction, float restitution); 
    void setPosition(glm::vec3 _position); 
    void setMass(float _mass); 
    void setRestitution(float _restitution); 
    void setFriction(float _friction); 
    std::string getName() const { return name; } 
    btCollisionShape* getShape() { return mShape; } 
    btRigidBody* getBody() { return rigidBody; } 
    int getIndex() const { return index; } 
private: 
    btCollisionShape* mShape; 
    btRigidBody* rigidBody; 
    std::string name; 
    int index; 
    //btDefaultMotionState * mMotionState; 
}; 

class World 
{ 

protected: 
    World(); 
public: 
    enum shapeTypes 
    { 
     sphere, 
     cube, 
     capsule 
    }; 
    static World * gameWorld(); 
    void init(); 
    btDiscreteDynamicsWorld* physicsWorld; 
    std::vector<btBoxShape> hitboxes; 
    mDebugDraw debugDrawer; 
    void drawWireframe(); 
    mRigidBody* getRigidBody(std::string name) const; 
    void addRigidBody(mRigidBody* _body, std::string _name); 
    std::map<std::string, mRigidBody *> getMap() { return mRigidBodies; } 
private: 
    static World *mInstance; 
    std::map<std::string, mRigidBody *> mRigidBodies; 
}; 

大半は、私は2つのコンストラクタを定義していますworld.hで次の2行から来ます。

mRigidBody(std::string name, World::shapeTypes type, glm::vec3 extent, glm::vec3 startposition); 
mRigidBody(std::string name, World::shapeTypes type, glm::vec3 extent, glm::vec3 startPosition, float mass, float friction, float restitution); 

エラーの完全な一覧を示します。

1> main.cpp 
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared 
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody' 
1> World.cpp 
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared 
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody' 
1>c:\repo\bustle\src\world.cpp(52): error C2511: 'mRigidBody::mRigidBody(std::string,World::shapeTypes,glm::vec3,glm::vec3)': overloaded member function not found in 'mRigidBody' 
1> c:\repo\bustle\include\world.h(73): note: see declaration of 'mRigidBody' 
1>c:\repo\bustle\src\world.cpp(62): error C2597: illegal reference to non-static member 'mRigidBody::mShape' 
1>c:\repo\bustle\src\world.cpp(65): warning C4244: 'argument': conversion from 'glm::tvec3<float,0>::length_type' to 'btScalar', possible loss of data 
1>c:\repo\bustle\src\world.cpp(65): error C2597: illegal reference to non-static member 'mRigidBody::mShape' 
1>c:\repo\bustle\src\world.cpp(68): error C2597: illegal reference to non-static member 'mRigidBody::mShape' 
1>c:\repo\bustle\src\world.cpp(74): error C2597: illegal reference to non-static member 'mRigidBody::mShape' 
1>c:\repo\bustle\src\world.cpp(74): error C2512: 'btRigidBody': no appropriate default constructor available 
1> c:\repo\bustle\bullet\src\bulletdynamics\vehicle\btwheelinfo.h(17): note: see declaration of 'btRigidBody' 
1>c:\repo\bustle\src\world.cpp(76): error C2671: 'mRigidBody::{ctor}': static member functions do not have 'this' pointers 
1>c:\repo\bustle\src\world.cpp(79): error C2511: 'mRigidBody::mRigidBody(std::string,World::shapeTypes,glm::vec3,glm::vec3,float,float,float)': overloaded member function not found in 'mRigidBody' 
1> c:\repo\bustle\include\world.h(73): note: see declaration of 'mRigidBody' 
1>c:\repo\bustle\src\world.cpp(80): error C2597: illegal reference to non-static member 'mRigidBody::name' 
1>c:\repo\bustle\src\world.cpp(91): error C2597: illegal reference to non-static member 'mRigidBody::mShape' 
1>c:\repo\bustle\src\world.cpp(94): warning C4244: 'argument': conversion from 'glm::tvec3<float,0>::length_type' to 'btScalar', possible loss of data 
1>c:\repo\bustle\src\world.cpp(94): error C2597: illegal reference to non-static member 'mRigidBody::mShape' 
1>c:\repo\bustle\src\world.cpp(97): error C2597: illegal reference to non-static member 'mRigidBody::mShape' 
1>c:\repo\bustle\src\world.cpp(104): error C2227: left of '->calculateLocalInertia' must point to class/struct/union/generic type 
1>c:\repo\bustle\src\world.cpp(106): error C2597: illegal reference to non-static member 'mRigidBody::mShape' 
1>c:\repo\bustle\src\world.cpp(107): error C2671: 'mRigidBody::{ctor}': static member functions do not have 'this' pointers 
1>c:\repo\bustle\src\world.cpp(107): error C2227: left of '->rigidBody' must point to class/struct/union/generic type 
1>c:\repo\bustle\src\world.cpp(108): error C2671: 'mRigidBody::{ctor}': static member functions do not have 'this' pointers 
1>c:\repo\bustle\src\world.cpp(108): error C2597: illegal reference to non-static member 'mRigidBody::name' 
1> State_Tutorial.cpp 
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared 
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody' 
1> State_MainMenu.cpp 
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared 
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody' 
1> State_Loading.cpp 
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared 
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody' 
1> State_Gameplay.cpp 
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared 
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody' 
1> State_EndRound.cpp 
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared 
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody' 
1>c:\repo\bustle\src\state_endround.cpp(530): warning C4018: '<': signed/unsigned mismatch 
1> State_BulletTest.cpp 
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared 
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody' 
1>c:\repo\bustle\src\state_bullettest.cpp(18): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'mRigidBody' 
1> c:\repo\bustle\src\state_bullettest.cpp(18): note: No constructor could take the source type, or constructor overload resolution was ambiguous 
1>c:\repo\bustle\src\state_bullettest.cpp(18): error C2512: 'mRigidBody': no appropriate default constructor available 
1> c:\repo\bustle\include\world.h(73): note: see declaration of 'mRigidBody' 
1>c:\repo\bustle\src\state_bullettest.cpp(19): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'mRigidBody' 
1> c:\repo\bustle\src\state_bullettest.cpp(19): note: No constructor could take the source type, or constructor overload resolution was ambiguous 
1>c:\repo\bustle\src\state_bullettest.cpp(19): error C2512: 'mRigidBody': no appropriate default constructor available 
1> c:\repo\bustle\include\world.h(73): note: see declaration of 'mRigidBody' 
1> Sprite.cpp 
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared 
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody' 
1>c:\repo\bustle\src\sprite.cpp(167): warning C4018: '>': signed/unsigned mismatch 
1> Player.cpp 
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared 
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody' 
1> Passenger.cpp 
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared 
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody' 
1> Kinematic.cpp 
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared 
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody' 
1> GameObject.cpp 
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared 
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody' 
1> GameManager.cpp 
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared 
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody' 
1>c:\repo\bustle\src\gamemanager.cpp(49): warning C4316: 'State_BulletTest': object allocated on the heap may not be aligned 16 
1> DisplayHandler.cpp 
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared 
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody' 
1> DebugManager.cpp 
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared 
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody' 
1> CollisionBoxes.cpp 
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared 
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody' 
1> Collision.cpp 
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name 
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes' 
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared 
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody' 
1>c:\repo\bustle\src\collision.cpp(158): warning C4018: '<': signed/unsigned mismatch 
1> Generating Code... 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

私は今これで一日中苦労しています。

+0

あなたは他のクラスの前に 'World'を宣言前進しようとしたことがありますか? –

+5

は、前方宣言と循環依存関係の解決について学ぶ必要があるようです。 – jaggedSpire

+3

'World'は使用後に宣言されます。 'World'の' mRigidBody'を参照する 'mRigidBody'の宣言の上に' World'の宣言を移動します。 – lcs

答えて

1

Worldが宣言される前に使用されます。 mRigidBodyのコンストラクタの定義ではWorld::shapeTypesを参照しますが、Worldはファイルの後半でのみ定義されます。 mRigidBodyの前にWorldの定義を入れてみてください。 Worldを定義する前にforward declaremRigidBodyにする必要があります。 mRigidBodyクラス定義の前に

+0

ありがとうございました! –

1

挿入1行:

class World; 
class mRigidBody 
+0

これでは十分ではありません。 'mRididBod'は' World'だけでなく 'World :: shapeTypes'を使います。 –

関連する問題