Reputation: 11
I've been looking for an answer for 2 days; I'm at a complete loss.
I've got...
struct shipDef
{
int mBaseHealth;
b2BodyDef mBodyDef;
};
...and in another file...
b2Body* b2World::CreateBody(const b2BodyDef* def)
{
//...
}
...and also...
shipDef * Game::getShipDef(const char* shipDefID)
{
std::pair<std::multimap<std::string,shipDef*>::iterator, std::multimap<std::string,shipDef*>::iterator> iteratorPair = mShipDefMap.equal_range(shipDefID);
std::size_t shipDefIDSize = std::distance( iteratorPair.first, iteratorPair.second );
std::size_t randomSoundIndex = std::rand() % shipDefIDSize;
std::advance( iteratorPair.first, randomSoundIndex );
return iteratorPair.first->second;
}
I'm calling...
mPhysicsBody = physicsWorld->CreateBody(Game::getInstance()->getShipDef(shipType).mBodyDef);
I'm getting an error:
expression must have class type
on the call to CreateBody.
I've tried every arrangement of the 'address of' operator I can think of and I've been all up and down google and stack overflow.
edited to include "b2BodyDef mBodyDef;"
Upvotes: 1
Views: 239
Reputation: 32182
If getShipDef
returns a pointer you have to use the ->
operator to access its members:
mPhysicsBody = physicsWorld->CreateBody(
Game::getInstance()->getShipDef(shipType)->mBodyDef
);
If a
is a pointer the expression a->b
is equivalent to (*a).b
so in your case you could have also written
mPhysicsBody = physicsWorld->CreateBody(
(*(Game::getInstance()->getShipDef(shipType))).mBodyDef
);
Upvotes: 3