Sign in to follow this  
Ubermeowmix

Getting lost with vector call in class

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
You defined vector<> to store objects
[CODE]
vector<EffectorVector> m_CurrEffectVec;
[/CODE]

But try to put pointer in there.
[CODE]
m_CurrEffectVec.push_back(new EffectorVector(type, time, str) );
[/CODE]

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this