Vector is not a Template?
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;
OmniOwl
Software Developer, Indie Game Developer & Architect of Play
Updated on July 29, 2022Comments
-
OmniOwl 5 monthsI 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 templateThe 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); }; #endifErrors 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-appError 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-appError 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-appError 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 over 9 yearsThank you. I used the first tip which solved it. Using the namespace would most likely have solved it too. -
OmniOwl over 9 yearsThe other guy listed more than one solution so I accepted his, though I up-voted yours too for effort! :3 -
Shafik Yaghmour over 9 years@Vipar No worries, you should pick the answer that helped you the most. -
Hiura over 9 yearsKeep in mind that using directives are not recommended in header files.
-
hmfarimani over 5 yearsdon't forget #include <vector> -
Ganesh S over 3 yearsI also had to do #include<vector> further in addition to above solution as I got a error std has no member vector -
Admin 11 monthsBuilding on what Ganesh said, if you arrived here anytime after 2019, you need #include<vector> and the std::vector to use a vector.