C++ Class generates no matching function and known conversion errors -


i've been learning box2d & c++ , managed create simple simulation in testbed, i'm trying take simulation out of testbed , integrate sdl shell.

however class, formerly worked in testbed generating errors when try instantiate , i'm bit confused why worked in testbed throwing out variable conversion errors.

this class:

    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 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( );         m_body->setgravityscale(5);//cancel gravity (use -1 reverse gravity, etc)         }     ~ball(){}     }; 

here program:

//footest class member variable std::vector<ball*> balls;  b2body* body;  int main (int argc, char* argv[]) {     // define gravity vector.     b2vec2 gravity(0.0f, -10.0f);      // construct world object, hold , simulate rigid bodies.     b2world world(gravity);      //add ball entity scene in constructor     ball* ball = new ball(world, 1);        // fails here     balls.push_back(ball);      // prepare simulation. typically use time step of 1/60 of     // second (60hz) , 10 iterations. provides high quality simulation     // in game scenarios.     float32 timestep = 1.0f / 60.0f;     int32 velocityiterations = 6;     int32 positioniterations = 2;      // our little game loop.     (int32 = 0; < 60; ++i)     {         // instruct world perform single step of simulation.         // best keep time step , iterations fixed.         world.step(timestep, velocityiterations, positioniterations);          // print position , angle of body.         b2vec2 position = body->getposition();         float32 angle = body->getangle();          printf("%4.2f %4.2f %4.2f\n", position.x, position.y, angle);     }      // when world destructor called, bodies , joints freed. can     // create orphaned pointers, careful world management.      return 0;  } 

this generated error:

c:\users\chris\my programs\_c++\keepie uppie\main.cpp||in function 'int main(int, char**)':| c:\users\chris\my programs\_c++\keepie uppie\main.cpp|20|error: no matching function call 'ball::ball(b2world&, int)'| c:\users\chris\my programs\_c++\keepie uppie\main.cpp|20|note: candidates are:| c:\users\chris\my programs\_c++\keepie uppie\objects.h|15|note: ball::ball(b2world*, float)| c:\users\chris\my programs\_c++\keepie uppie\objects.h|15|note:   no known conversion argument 1 'b2world' 'b2world*'| c:\users\chris\my programs\_c++\keepie uppie\objects.h|7|note: ball::ball(const ball&)| c:\users\chris\my programs\_c++\keepie uppie\objects.h|7|note:   candidate expects 1 argument, 2 provided| 

if call constructor

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

i following errors

obj\debug\main.o||in function `main':| c:\users\chris\my programs\_c++\keepie uppie\main.cpp|17|undefined reference `b2world::b2world(b2vec2 const&)'| c:\users\chris\my programs\_c++\keepie uppie\main.cpp|35|undefined reference `b2world::step(float, int, int)'| c:\users\chris\my programs\_c++\keepie uppie\main.cpp|47|undefined reference `b2world::~b2world()'| c:\users\chris\my programs\_c++\keepie uppie\main.cpp|47|undefined reference `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 `vtable b2circleshape'| obj\debug\main.o||in function `zn4ballc1ep7b2worldf':| c:\users\chris\my programs\_c++\keepie uppie\objects.h|24|undefined reference `b2world::createbody(b2bodydef const*)'| c:\users\chris\my programs\_c++\keepie uppie\objects.h|34|undefined reference `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 `vtable b2circleshape'| ||=== build finished: 8 errors, 0 warnings (0 minutes, 2 seconds) ===| 

in line

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

you use constructor of ball not exist, since ones available ball(b2world* world, float radius) , copy constructor. if want use constructor declared, need pass pointer world:

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

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -