Vector is not a Template?

69,413

Solution 1

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;

Solution 2

Since I don't see any using statements in your code sample, I am pretty sure you need to add std:: to your vector declaration, like so:

std::vector<sf::Texture> textureList;
Share:
69,413
OmniOwl
Author by

OmniOwl

Software Developer, Indie Game Developer & Architect of Play

Updated on July 29, 2022

Comments

  • OmniOwl
    OmniOwl 5 months

    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

  • OmniOwl
    OmniOwl over 9 years
    Thank you. I used the first tip which solved it. Using the namespace would most likely have solved it too.
  • OmniOwl
    OmniOwl over 9 years
    The other guy listed more than one solution so I accepted his, though I up-voted yours too for effort! :3
  • Shafik Yaghmour
    Shafik Yaghmour over 9 years
    @Vipar No worries, you should pick the answer that helped you the most.
  • Hiura over 9 years
    Keep in mind that using directives are not recommended in header files.
  • hmfarimani
    hmfarimani over 5 years
    don't forget #include <vector>
  • Ganesh S
    Ganesh S over 3 years
    I also had to do #include<vector> further in addition to above solution as I got a error std has no member vector
  • Admin
    Admin 11 months
    Building on what Ganesh said, if you arrived here anytime after 2019, you need #include<vector> and the std::vector to use a vector.