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-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
vector is a template class, which can be instantiated with a type, in the format: vector<int> , vector<double> , vector<string> . The same template class can be used to handle many types, instead of repeatably writing codes for each of the type.
Vectors, or std::vector , are a template class in the STL (Standard Template Library). But what does that mean? They are a more flexible, refined, and efficient replacement for arrays, which are used in the C programming language (and on which the C++ language is based).
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With