矢量不是模板
“矢量”一词用红色加下划线.为什么这不行?为什么它告诉我这是一个模板,为什么这个程序的意思不会奏效?
#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
我得到的错误(毫无疑问,这些产生的错误来自上面这部分的错误):
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-appError 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-appError 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-appError 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-appError 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-appError 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-appError 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-app11 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
解决方法
std::vector<sf::Texture> textureList;
或者你可以使用一个using语句:
using std::vector; vector<sf::Texture> textureList;