Jump to content
  • Advertisement
Sign in to follow this  
Ubermeowmix

Getting lost with vector call in class

This topic is 2243 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Why can't I call the vector created in the class file?

#include <vector>
// includes etc removed but class works fine except for vector
class NonPlayerChar
{
public:
NonPlayerChar(string, double, double, double);
~NonPlayerChar(void);

private:
vector<EffectorVector> m_CurrEffectVec;
}

void NonPlayerChar::AddEffector(string type, int time, double str)
{
m_CurrEffectVec.push_back(new EffectorVector(type, time, str) );
};

// called globally in main
vector<NonPlayerChar> myEnemies;

// called within main function
myEnemies[chooseEnemy-1].AddEffector("bleed", 2000, 3.5f);

I don't understand why it won't let me action this code, it doesn't need to be a pointer as I'm not returning the information to the main function.

Share this post


Link to post
Share on other sites
Advertisement
You defined vector<> to store objects

vector<EffectorVector> m_CurrEffectVec;


But try to put pointer in there.

m_CurrEffectVec.push_back(new EffectorVector(type, time, str) );

Share this post


Link to post
Share on other sites
Okay I'm getting lost again here.

main->callBaddieVector[BaddieClassObject]->CheckParasiteVector[ParasiteClassObject]->m_health

where CheckParasiteVector is generated within the class constructor for the BaddieClassObject.

I thought that vector calls were already created on the heap so I don't need to create a pointer unless I'm calling m_health through the function call?

Share this post


Link to post
Share on other sites
Right I fixed it, I was assigning the declaration of the 2nd vector in the class as a pointer, this didn't sit well with the iterator loop. Thanks for the help guys.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!