Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

std::vector error

Started by programci_84 6 replies 1.1k views
Original Post
programci_84
programci_84
Hi all, I have a class called GFizik. This has some members and one of'em is a vector type array:
typedef std::vector<NxActor*> ActorVec;
...

class GFizik
{
public:
 ...
 HRESULT AddActor (NxActorDesc Desc);
 NxActor* RigidBody   (LPCSTR name);
 NxActor* RigidBody   (const UINT index);
 ...
 ActorVec pActors;
};
With AddActor(), I'm adding an NxActor* element to pActors vector array by using vector's push_back() function. And with RigidBody() functions, I'm getting an element of pActors array by its name or index. For example, to access by index:
NxActor* GFizik::RigidBody(const UINT index)
{
  if (index < 0 || index > pActors.size()) return NULL;
  return pActors [index];
}
My app has a GFizik type member (m_Physics). If I write somewhere in my code,
m_Physics.RigidBody(0)->SetGlobalPose (...)
then my compiler gives me an error: ... error C2668: 'GFizik::RigidBody' : ambiguous call to overloaded function ... could be 'NxActor *GFizik::RigidBody(LPCSTR)' ... or 'NxActor *GFizik::RigidBody(const UINT)' But if I write UINT ind = 0; m_Physics.RigidBody(ind)->SetGlobalPose (...); no error occurs. Also if I'm using RigidBody() function like; m_Physics.RigidBody ("plane1")->SetGlobalPose(...) no error occurs again. How can I solve my problem? Thanks in advance.
There's no "hard", and "the impossible" takes just a little time.
DevFred
DevFred
Quote:
Original post by programci_84
#typedef std::vector ActorVec;

remove the # symbol.
SiCrane
SiCrane
Your problem is that 0 is both an integer and a null pointer constant. I would recommend just changing your RigidBody functions so that they don't both share the same name. Otherwise you can cast 0 to the correct type when you need it.
ToohrVyk
ToohrVyk
Mark zero as being unsigned.
m_Physics.RigidBody(0u)->SetGlobalPose (...)
programci_84
programci_84
Quote:
remove the # symbol.


Sorry. There's no # symbol in my code, I made a mistake when I'm writing here.
There's no "hard", and "the impossible" takes just a little time.
DevFred
DevFred
Why are you writing new source code for the forum? Just copy and paste.
programci_84
programci_84
Quote:
Original post by ToohrVyk
Mark zero as being unsigned.
m_Physics.RigidBody(0u)->SetGlobalPose (...)


Thanks ToohrVyk, solved :)

There's no "hard", and "the impossible" takes just a little time.
iMalc
iMalc
Or, change the first overload to take a std::string instead.
Then wait patiently for nullptr.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.