Vector is not a Template?

OmniOwl picture OmniOwl · May 23, 2013 · Viewed 56.1k times · Source

I am currently trying to follow a tutorial on making a simple 2D tile engine for top-down RPGs. For some reason though I get the intellisense error

vector is not a template

The word "vector" is underlined with red. Why does this not work? Why is it telling me that it's a template, and why does the mean the program won't work?

#ifndef _IMAGEMANAGER_H
#define _IMAGEMANAGER_H

#include <vector>
#include <SFML\Graphics.hpp>

class ImageManager
{
private:
    vector<sf::Texture> textureList;

public:
    ImageManager();
    ~ImageManager();

    void AddTexture(sf::Texture& texture);
    sf::Texture& GetTexture(int index);
};
#endif

Errors I get (no doubt some of these spawn from the error of this part above):

  • Error 1 error C2143: syntax error : missing ';' before '<' c:\users\vipar\dropbox\computer science\programming\visual studio 2012\projects\sfml-app\sfml-app\imagemanager.h 10 1 sfml-app

  • Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\vipar\dropbox\computer
    science\programming\visual studio
    2012\projects\sfml-app\sfml-app\imagemanager.h 10 1 sfml-app

  • Error 3 error C2238: unexpected token(s) preceding ';' c:\users\vipar\dropbox\computer science\programming\visual studio 2012\projects\sfml-app\sfml-app\imagemanager.h 10 1 sfml-app

  • Error 4 error C2143: syntax error : missing ';' before '<' c:\users\vipar\dropbox\computer science\programming\visual studio 2012\projects\sfml-app\sfml-app\imagemanager.h 10 1 sfml-app

  • Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\vipar\dropbox\computer
    science\programming\visual studio
    2012\projects\sfml-app\sfml-app\imagemanager.h 10 1 sfml-app

  • Error 6 error C2238: unexpected token(s) preceding ';' c:\users\vipar\dropbox\computer science\programming\visual studio 2012\projects\sfml-app\sfml-app\imagemanager.h 10 1 sfml-app

  • Error 7 error C2065: 'textureList' : undeclared identifier c:\users\vipar\dropbox\computer science\programming\visual studio 2012\projects\sfml-app\sfml-app\imagemanager.cpp 22 1 sfml-app

  • Error 8 error C2143: syntax error : missing ';' before '<' c:\users\vipar\dropbox\computer science\programming\visual studio 2012\projects\sfml-app\sfml-app\imagemanager.h 10 1 sfml-app

  • Error 9 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\vipar\dropbox\computer
    science\programming\visual studio
    2012\projects\sfml-app\sfml-app\imagemanager.h 10 1 sfml-app

  • Error 10 error C2238: unexpected token(s) preceding ';' c:\users\vipar\dropbox\computer science\programming\visual studio 2012\projects\sfml-app\sfml-app\imagemanager.h 10 1 sfml-app

  • 11 IntelliSense: vector is not a template c:\Users\Vipar\Dropbox\Computer Science\Programming\Visual
    Studio 2012\Projects\sfml-app\sfml-app\ImageManager.h 10 2 sfml-app

Answer

0x499602D2 picture 0x499602D2 · May 23, 2013

vector is from the std namespace, so you must use std:: to specify:

std::vector<sf::Texture> textureList;

Or you can use a using statement:

using std::vector;

vector<sf::Texture> textureList;