Reputation: 5835
class Game {
public:
void draw_string(const char *text, int x, int y, TTF_Font *font, SDL_Color color, bool center);
private:
void spawn_enemies(vector <Enemy*>& enemies);
};
I have that as the definition of a class, and the definition of spawn_enemies is as follows:
void Game::spawn_enemies(vector <Enemy*>& enemies) {
if (rand() % difficulty == 0) {
Enemy *enemy = new Enemy(screen, zombie_image);
enemies.push_back(enemy);
}
}
And then I call spawn_enemies:
game.spawn_enemies(enemies);
And I define enemies as:
vector<Enemy*> enemies;
Any idea of why I get this error:
error: no matching function for call to ‘Game::spawn_enemies(std::vector<Enemy*>&)’
note: candidate is:
note: void Game::spawn_enemies(int)
note: no known conversion for argument 1 from ‘std::vector<Enemy*>’ to ‘int’
Upvotes: 0
Views: 108
Reputation: 787
I wasn't doing "using namespace std;" on the header file, so it wasn't including vector, which was causing a lot of weird mistakes
This is why it is good to use std:: instead of using namespace std. It makes your code easier to understand and your code will still compile if they ever add Game or Enemy to the STL (Unlikely, I know). And it would allow you to add your own version of vector, min/max etc. if you really wanted to (I wouldn't recommend it though).
Upvotes: 2