c++ - Define an object in a .cpp file -
header file
class universe { public: universe(); ~universe(); private: chunkmanager chunkmanager; };
i want initialize chunkmanger
without using default constructor. however, constructor want use takes object. how make chunkmanager
object use correct constructor in .cpp file? want this:
universe::universe(){ world = new b2world(b2vec2(0, 0)); world->setallowsleeping(false); //i want because constructor want takes world object chunkmanager = new chunkmanager(world); player = new player(world); }
chunkmanager
in header object not pointer, chunkmanager = new chunkmanager(world);
wrong.
you can leave object , initialize this:
universe::universe() : chunkmanager(world) {
but don't have world
yet (unless can pass parameter). easiest solution make header have pointer:
private: chunkmanager* chunkmanager;
and .cpp ok.
edit: assume kenny ostram getting @ in comments since you've dynamically allocated chunkmanager
need sure delete
@ point (probably destructor) avoid memory leak.
Comments
Post a Comment