Can anyone help

for(std::vector<GameObject*>::size_type i = 0;
i != m_gameObjects.size(); i ++)


I am getting the error message: 'm_gameObjects' : attribute not found. With regards to this slither of code.



It sounds like m_gameObjects isn't defined. Perhaps you misspelled it, or declared it in a scope outside of where you're trying to access it.
I assumed that was the problem also. But another instance of m_gameObjects compiles successfully earlier in the same source file.
I may have defined it incorrectly...

std::vector<GameObject*> m_gameObjects;
You haven't shown us nearly enough code for us to be able to answer this.
It might be a scope issue.

m_gameObjects is defined in your class... but is the problematic for loop inside a class method? Is it in a static class method?

MikeyBoy is right, we're going to need to see more code. Specifically where and how m_gameObjects is defined... and where that for loop is.
#include "game.h"
#include "TextureManager.h"
#include <vector>
#include "GameObject.h"


typedef TextureManager TheTextureManager;


bool Game::init(const char* title, int xpos, int ypos, int width, int height, int flags)
{

if(SDL_Init(SDL_INIT_EVERYTHING) == 0)
{
m_pWindow = SDL_CreateWindow(title, xpos, ypos, width, height, flags);

if(m_pWindow != 0)
{
m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, 0);

if(m_pRenderer != 0)
{
SDL_SetRenderDrawColor(m_pRenderer, 255,255,255,255);
}

else
{
return false;
}
}

else
{
return false;
}
}

else
{
return false;
}

m_go = new GameObject();
m_player = new player();

m_go->load(100, 100, 128, 82, "animate");
m_player->load(300, 300, 128, 82, "animate");

m_gameObjects.push_back(m_go);
m_gameObjects.push_back(m_player);

if(!TheTextureManager::Instance()->load("assets/animate.png", "animate", m_pRenderer))
{
return false;
}

m_bRunning = true;

return true;




}


void Game::render()
{

SDL_RenderClear(m_pRenderer);

for(std::vector<GameObject*>::size_type i = 0;
i != m_gameObjects.size(); i ++)
[
m_gameobjects[i]->draw(m_pRenderer);
}

SDL_RenderPresent(m_pRenderer);

}


void Game::update()
{

for(std::vector<GameObject*>::size_type i = 0; i != m_gameObjects.size(); i ++)
{
m_gameObjects[i]->update();
}

}


void Game::handleEvents()
{
SDL_Event event;

if(SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:m_bRunning = false;
break;

default:
break;
}
}
}


void game::draw()
{
for(std::vector<GameObject*>::size_type i = 0; i != m_gameObjects.size(); i ++)
{
m_gameObjects[i]->draw(m_pRenderer);
}
}


void Game::clean()
{
SDL_DestroyWindow(m_pWindow);

SDL_DestroyRenderer(m_pRenderer);

SDL_Quit();
}
;

std::vector<GameObject*> m_gameObjects;

is in game.h
Please use code tags:

[code]put your code here[/code]

Anyway... I see a problem here:

1
2
3
4
5
for(std::vector<GameObject*>::size_type i = 0; 
 i != m_gameObjects.size(); i ++)
 [   // <- This should be a { brace, not a [ bracket
 m_gameobjects[i]->draw(m_pRenderer);
 }
sorry I'm new to programming.
This is the contents of game.h


#include "GameObject.h"
#include "player.h"
#include <vector>


GameObject* m_go;
GameObject* m_player;
std::vector<GameObject*> m_gameObjects;


class Game {
public:

Game(){}
~Game(){}





bool init(const char* title, int xpos, int ypos, int width, int height, int flags);

void render();
void update();
void handleEvents();
void clean();

bool running() {
return m_bRunning; }

private:

SDL_Window* m_pWindow;

SDL_Renderer* m_pRenderer;

int m_currentFrame;


bool m_bRunning;
};





#endif /*
defined (__Game__) */
Thanks Disch you nailed it. Really appreciate the help.
Topic archived. No new replies allowed.