Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;类不生成匹配函数和已知的转换错误 我一直在学习Box 2D和C++,并在测试平台中创建了一个简单的模拟,现在我尝试把模拟从测试平台中取出,并与SDL shell集成。_C++_Compiler Errors_Box2d - Fatal编程技术网

C++;类不生成匹配函数和已知的转换错误 我一直在学习Box 2D和C++,并在测试平台中创建了一个简单的模拟,现在我尝试把模拟从测试平台中取出,并与SDL shell集成。

C++;类不生成匹配函数和已知的转换错误 我一直在学习Box 2D和C++,并在测试平台中创建了一个简单的模拟,现在我尝试把模拟从测试平台中取出,并与SDL shell集成。,c++,compiler-errors,box2d,C++,Compiler Errors,Box2d,然而,以前在测试床上工作的类现在在我尝试实例化它时产生了错误,我有点困惑为什么它在测试床上工作得很好,但现在抛出了变量转换错误 这是我的班级: class Ball { public: bool m_contacting; b2Body* m_body; float m_radius; public: // Ball class constructor Ball(b2World* world

然而,以前在测试床上工作的类现在在我尝试实例化它时产生了错误,我有点困惑为什么它在测试床上工作得很好,但现在抛出了变量转换错误

这是我的班级:

    class Ball {
    public:
        bool m_contacting;
        b2Body* m_body;
        float m_radius;

    public:
        // Ball class constructor
        Ball(b2World* world, float radius) {
        m_contacting = false;
        m_body = NULL;
        m_radius = radius;

        //set up dynamic body, store in class variable
        b2BodyDef myBodyDef;
        myBodyDef.type = b2_dynamicBody;
        myBodyDef.position.Set(0, 20);
        m_body = world->CreateBody(&myBodyDef);

        //add circle fixture
        b2CircleShape circleShape;
        circleShape.m_p.Set(0, 0);
        circleShape.m_radius = m_radius; //use class variable
        b2FixtureDef myFixtureDef;
        myFixtureDef.shape = &circleShape;
        myFixtureDef.density = 1;
        myFixtureDef.restitution = 0.83f;
        m_body->CreateFixture(&myFixtureDef);
        m_body->SetUserData( this );
        m_body->SetGravityScale(5);//cancel gravity (use -1 to reverse gravity, etc)
        }
    ~Ball(){}
    };
这是我的节目:

//FooTest class member variable
std::vector<Ball*> balls;

b2Body* body;

int main (int argc, char* argv[]) {
    // Define the gravity vector.
    b2Vec2 gravity(0.0f, -10.0f);

    // Construct a world object, which will hold and simulate the rigid bodies.
    b2World world(gravity);

    //add ball entity to scene in constructor
    Ball* ball = new Ball(world, 1);        // Fails here
    balls.push_back(ball);

    // Prepare for simulation. Typically we use a time step of 1/60 of a
    // second (60Hz) and 10 iterations. This provides a high quality simulation
    // in most game scenarios.
    float32 timeStep = 1.0f / 60.0f;
    int32 velocityIterations = 6;
    int32 positionIterations = 2;

    // This is our little game loop.
    for (int32 i = 0; i < 60; ++i)
    {
        // Instruct the world to perform a single step of simulation.
        // It is generally best to keep the time step and iterations fixed.
        world.Step(timeStep, velocityIterations, positionIterations);

        // Now print the position and angle of the body.
        b2Vec2 position = body->GetPosition();
        float32 angle = body->GetAngle();

        printf("%4.2f %4.2f %4.2f\n", position.x, position.y, angle);
    }

    // When the world destructor is called, all bodies and joints are freed. This can
    // create orphaned pointers, so be careful about your world management.

    return 0;

}
如果我像这样调用构造函数

Ball* ball = new Ball(&world, 1);
我得到以下错误

obj\Debug\main.o||In function `main':|
C:\Users\Chris\My Programs\_C++\Keepie Uppie\main.cpp|17|undefined reference to `b2World::b2World(b2Vec2 const&)'|
C:\Users\Chris\My Programs\_C++\Keepie Uppie\main.cpp|35|undefined reference to `b2World::Step(float, int, int)'|
C:\Users\Chris\My Programs\_C++\Keepie Uppie\main.cpp|47|undefined reference to `b2World::~b2World()'|
C:\Users\Chris\My Programs\_C++\Keepie Uppie\main.cpp|47|undefined reference to `b2World::~b2World()'|
obj\Debug\main.o||In function `ZN13b2CircleShapeC1Ev':|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\..\include\Box2D\Collision\Shapes\b2CircleShape.h|65|undefined reference to `vtable for b2CircleShape'|
obj\Debug\main.o||In function `ZN4BallC1EP7b2Worldf':|
C:\Users\Chris\My Programs\_C++\Keepie Uppie\objects.h|24|undefined reference to `b2World::CreateBody(b2BodyDef const*)'|
C:\Users\Chris\My Programs\_C++\Keepie Uppie\objects.h|34|undefined reference to `b2Body::CreateFixture(b2FixtureDef const*)'|
obj\Debug\main.o||In function `ZN13b2CircleShapeD1Ev':|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\..\include\Box2D\Collision\Shapes\b2CircleShape.h|25|undefined reference to `vtable for b2CircleShape'|
||=== Build finished: 8 errors, 0 warnings (0 minutes, 2 seconds) ===|

您声明构造函数具有以下参数

Ball(b2World* world, float radius);
第一个参数是指向2World的指针。但是,您使用对2World的引用而不是指针来调用它

b2World world(gravity);

//add ball entity to scene in constructor
Ball* ball = new Ball(world, 1);        
世界不是指向世界的指针。所以这个声明

Ball* ball = new Ball(world, 1);
这是无效的

也许你是说

Ball* ball = new Ball( &world, 1 );

您声明构造函数具有以下参数

Ball(b2World* world, float radius);
第一个参数是指向2World的指针。但是,您使用对2World的引用而不是指针来调用它

b2World world(gravity);

//add ball entity to scene in constructor
Ball* ball = new Ball(world, 1);        
世界不是指向世界的指针。所以这个声明

Ball* ball = new Ball(world, 1);
这是无效的

也许你是说

Ball* ball = new Ball( &world, 1 );

您声明构造函数具有以下参数

Ball(b2World* world, float radius);
第一个参数是指向2World的指针。但是,您使用对2World的引用而不是指针来调用它

b2World world(gravity);

//add ball entity to scene in constructor
Ball* ball = new Ball(world, 1);        
世界不是指向世界的指针。所以这个声明

Ball* ball = new Ball(world, 1);
这是无效的

也许你是说

Ball* ball = new Ball( &world, 1 );

您声明构造函数具有以下参数

Ball(b2World* world, float radius);
第一个参数是指向2World的指针。但是,您使用对2World的引用而不是指针来调用它

b2World world(gravity);

//add ball entity to scene in constructor
Ball* ball = new Ball(world, 1);        
世界不是指向世界的指针。所以这个声明

Ball* ball = new Ball(world, 1);
这是无效的

也许你是说

Ball* ball = new Ball( &world, 1 );
排队

Ball* ball = new Ball(world, 1);
您使用不存在的
Ball
构造函数,因为唯一可用的构造函数是
Ball(b2World*world,float radius)
和复制构造函数。如果要使用声明的构造函数,需要将指针传递到world:

Ball* ball = new Ball(&world, 1);
排队

Ball* ball = new Ball(world, 1);
您使用不存在的
Ball
构造函数,因为唯一可用的构造函数是
Ball(b2World*world,float radius)
和复制构造函数。如果要使用声明的构造函数,需要将指针传递到world:

Ball* ball = new Ball(&world, 1);
排队

Ball* ball = new Ball(world, 1);
您使用不存在的
Ball
构造函数,因为唯一可用的构造函数是
Ball(b2World*world,float radius)
和复制构造函数。如果要使用声明的构造函数,需要将指针传递到world:

Ball* ball = new Ball(&world, 1);
排队

Ball* ball = new Ball(world, 1);
您使用不存在的
Ball
构造函数,因为唯一可用的构造函数是
Ball(b2World*world,float radius)
和复制构造函数。如果要使用声明的构造函数,需要将指针传递到world:

Ball* ball = new Ball(&world, 1);

您将引用传递到
世界
,似乎您的构造函数期望
世界
您将引用传递到
世界
,似乎您的构造函数期望
世界
您将引用传递到
世界
,您的构造函数似乎期望您传递对
世界的引用
&world
,如果我使用
新球(&world,1),则您的构造函数似乎期望
&world
Hmm我得到了很多未定义的引用错误:“obj\Debug\main.o|In function
main':|C:\Users\Chris\My Programs\u C++\Keepie Uppie\main.cpp | 17 |对
b2World::b2World(b2Vec2 const&)的未定义引用| C:\Users\Chris\My Programs\u C++\Keepie Uppie\main.cpp | 35 |对
b2World::Step的未定义引用(float,int,int,int,int)“|C:\Users\Chris\My Programs\\u C++\Keepie Uppie\main.cpp | 47 |对
b2World::~b2World()”|“@Funk247你认为我建议在哪里写语句new Ball(&world,1);”?在你原始帖子的最后一行,我修改了我的代码以反映这一点,但只发布了最后的字符。对不起,我太懒了。啊,你是对的,这解决了我的问题,现在我的类正在生成错误!谢谢你的帮助。嗯,如果我使用
newball(&world,1)我得到了很多未定义的引用错误:“obj\Debug\main.o|In function
main':|C:\Users\Chris\My Programs\u C++\Keepie Uppie\main.cpp | 17 |对
b2World::b2World(b2Vec2 const&)的未定义引用| C:\Users\Chris\My Programs\u C++\Keepie Uppie\main.cpp | 35 |对
b2World::Step的未定义引用(float,int,int,int,int)“|C:\Users\Chris\My Programs\\u C++\Keepie Uppie\main.cpp | 47 |对
b2World::~b2World()”|“@Funk247你认为我建议在哪里写语句new Ball(&world,1);”?在你原始帖子的最后一行,我修改了我的代码以反映这一点,但只发布了最后的字符。对不起,我太懒了。啊,你是对的,这解决了我的问题,现在我的类正在生成错误!谢谢你的帮助。嗯,如果我使用
newball(&world,1)我得到了很多未定义的引用错误:“obj\Debug\main.o|In function
main':|C:\Users\Chris\My Programs\u C++\Keepie Uppie\main.cpp | 17 |对
b2World::b2World(b2Vec2 const&)的未定义引用| C:\Users\Chris\My Programs\u C++\Keepie Uppie\main.cpp | 35 |对
b2World::Step的未定义引用(float,int,int,int,int)“|C:\Users\Chris\My Programs\\u C++\Keepie Uppie\main.cpp | 47 |对
b2World::~b2World()”|“@Funk247你认为我建议在哪里写语句new Ball(&world,1);”?在你原始帖子的最后一行,我修改了我的代码以反映这一点,但只发布了最后的字符。对不起,我太懒了。啊,你是对的,这解决了我的问题,现在我的类正在生成错误!谢谢你的帮助。嗯,如果我使用
newball(&world,1)我得到很多未定义的引用错误:“obj\Debug\main.o|In function
main':|C:\Users\Chris\My Programs\\u C++\Keep