[FIXED]SDL2 Spawn Multiple Objects

Hello guys, i’m new with SDL2 lib. Anyone can help me? I want to know how can i spawn multiple objects (like trees, grass…), i tried by using vectors but that not work for me. I have an Object class, there is setDest, setSource, and setImage functions for rendering, i have defined a vector objContainer when i try to call obContainer[currentObj].setImage(".bmp", ren) or objContainer.push_back(…) this crushed my compiler.

Please show relevant code and I can check it out for you, and maybe spot some errors made in it.
If you don’t want to post the code here, you can upload it to github etc and then post the link to it here.

class Game

void loop();
void update();
void input();
void render();
void draw(Object o);

SDL_Renderer* ren;
SDL_Window* win;
bool isRunning, flag = true;
int count;
int frameCount, timerFPS, previousFrame = 0, lastFrame, timeOut;
int turretPos, yPos, turretVel;
Player player; //PLAYER A DIBUJAR
int birdFlying, birdFalling, flyingVel, fallingVel;
float playerPos, playerVel, G;

Object *enemy = new Object;
vector<Object> objContainer;

SDL_CreateWindowAndRenderer(620, 480, 0, &win, &ren);
SDL_SetWindowTitle(win, “My GameEngine”);
isRunning = true;
count = 0;

for(int i = 0; i < 5; i++)
    enemy->setImage("turret.bmp", ren);
    enemy->setSource(0, 0, 100, 300);


this is my Object class:

void Object::setDest(int x, int y, int w, int h)
dest.x = x;
dest.y = y;
dest.w = w;
dest.h = h;
void Object::setSource(int x, int y, int w, int h)
src.x = x;
src.y = y;
src.w = w;
src.h = h;
void Object::setImage(string filename, SDL_Renderer* ren)
const char *f = filename.c_str();

SDL_Surface* surf;

surf = SDL_LoadBMP(f);
texture = SDL_CreateTextureFromSurface(ren,surf);


Now i can spawn multiple objects but i can’t set independent movements. I thought about using something like a typedef struct enemyVar{ Object *enemy = new Object; xPos, yPos… }; to get their coordinates or another var, like health…I try to write some function that can give me those variables to manipulate, something like objContainer[i].xPos +=…

Do you want the objects/turrets to move around during runtime or do you just want to position them at the startup of the program and then be finished with their movements?

And if you want the objects/turrets to move during runtime, do you want them to move randomly around or a fixed path?

I want to move during runtime with a timeOut to disappear, then destroy the texture i think

Should the object(s) move randomly around or in a fixed path before it disappears?

fixed path in the X axis, and randomdly for the Y axis