Getting lost with vector call in class

Started by
4 comments, last by Ubermeowmix 11 years, 8 months ago
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.
If you get near a point, make it!
Advertisement
I read your code wrong. What is the problem. What does the compiler say?
error C2440: 'initializing' : cannot convert from 'std::_Vector_iterator<_Myvec>' to 'std::_Vector_iterator<_Myvec>'
If you get near a point, make it!
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) );
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?
If you get near a point, make it!
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.
If you get near a point, make it!

This topic is closed to new replies.

Advertisement