Vector of pointers , undefined class list , beg for help?

I try to use the vector of pointer to replace the vector of objects .
but the carlist become undefined …
why ? how could i do ?

void ofApp::setup(){

numCars =800;
for(int i =0;i<numCars;i++){
	Car c ;
	carList.push_back(new Car());


void ofApp::update(){

numCars =y;

//update the list of cars
for (int i =0;i<numCars;i++){
	carList[i].update();     // carList become undefined 


carList is undefined
here is the app.h:

int numCars;
vector<Car*> carList;
  1. It doesn’t look like carList is undefined, but the way you’re calling update() is triggering errors. You should switch that to carList[i]->update(); The arrow operator (->) lets you use the thing you’re pointing to, instead of the pointer itself.

  2. Your for loop in setup() looks like it’s not doing what you think it’s doing? What you’re doing there is creating a new Car called c, and then just throwing it away. If you want to create a vector of 800 objects, and call setup() on all of them, try this instead:

for(int i =0;i<numCars;i++){
    carList.push_back(new Car());

The function back() on the vector will give you the last object, which in this case will be the Car * that just got created.

Thx ! but there is also a problem in draw .
void ofApp::draw(){


ofDrawBitmapString(ofToString(pSensor.BPM), 10, 200);
//draw the single car

//draw the list of cars
for (int i =0;i<numCars;i++){



Error 3 error C3867: ‘Car::draw’: function call missing argument list; use ‘&Car::draw’ to create a pointer to member
what should i do ?!

You’re missing the () on your draw call :wink:




haha , cheer ,
Thanks ,admsyn !! It works !

Admsyn! I’m sorry !
another problem !

void Car::update(){


float timeY = ofGetElapsedTimef() *0.05;
 amplitude = thisRadius + ofRandom(-0.5, 0.5);

yPos = ofGetWindowHeight()/2 + amplitude * sin(timeY)+x;

float timeX = ofGetElapsedTimef() * 0.05;

float homeX = ofGetWindowWidth()/2;

xPos = ofGetWindowWidth()/2 + amplitude* cos(timeX);


void Car::draw(){


ofCircle(xPos, yPos, width);}

I want to use the bpm sent by pulsesensor to control the width , but it doesn’t work !
However , I can use the bpm to control the numcars in app…
what should i do ?

ps: the y =o
so ofSetColor(y,y,y); should be ofSetColor(0,0,0);