我目前正在尝试按照教程为自上而下的RPG制作一个简单的2D磁贴引擎。出于某种原因,虽然我得到了智能感知错误
vector is not a template
“矢量”一词用红色加下划线。为什么这不起作用?为什么它告诉我它是一个模板,为什么程序不起作用呢?
#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
我得到的错误(毫无疑问,其中一些错误来自上述部分的错误):
错误1错误C2143:语法错误:缺少';'在'&lt;'之前c:\ users \ vipar \ dropbox \ computer science \ programming \ visual studio 2012 \ projects \ sfml-app \ sfml-app \ imagemanager.h 10 1 sfml-app
错误2错误C4430:缺少类型说明符 - 假定为int。注意:C ++不支持default-int c:\ users \ vipar \ dropbox \ computer
科学\编程\视觉工作室
2012 \ projects \ sfml-app \ sfml-app \ imagemanager.h 10 1 sfml-app错误3错误C2238:';'之前的意外令牌c:\ users \ vipar \ dropbox \ computer science \ programming \ visual studio 2012 \ projects \ sfml-app \ sfml-app \ imagemanager.h 10 1 sfml-app
错误4错误C2143:语法错误:缺少';'在'&lt;'之前c:\ users \ vipar \ dropbox \ computer science \ programming \ visual studio 2012 \ projects \ sfml-app \ sfml-app \ imagemanager.h 10 1 sfml-app
错误5错误C4430:缺少类型说明符 - 假定为int。注意:C ++不支持default-int c:\ users \ vipar \ dropbox \ computer
科学\编程\视觉工作室
2012 \ projects \ sfml-app \ sfml-app \ imagemanager.h 10 1 sfml-app错误6错误C2238:';'之前的意外令牌c:\ users \ vipar \ dropbox \ computer science \ programming \ visual studio 2012 \ projects \ sfml-app \ sfml-app \ imagemanager.h 10 1 sfml-app
错误7错误C2065:'textureList':未声明的标识符c:\ users \ vipar \ dropbox \ computer science \ programming \ visual studio 2012 \ projects \ sfml-app \ sfml-app \ imagemanager.cpp 22 1 sfml-app
错误8错误C2143:语法错误:缺少';'在'&lt;'之前c:\ users \ vipar \ dropbox \ computer science \ programming \ visual studio 2012 \ projects \ sfml-app \ sfml-app \ imagemanager.h 10 1 sfml-app
错误9错误C4430:缺少类型说明符 - 假定为int。注意:C ++不支持default-int c:\ users \ vipar \ dropbox \ computer
科学\编程\视觉工作室
2012 \ projects \ sfml-app \ sfml-app \ imagemanager.h 10 1 sfml-app错误10错误C2238:';'之前的意外令牌c:\ users \ vipar \ dropbox \ computer science \ programming \ visual studio 2012 \ projects \ sfml-app \ sfml-app \ imagemanager.h 10 1 sfml-app
11智能感知:矢量不是模板c:\ Users \ Vipar \ Dropbox \ Computer Science \ Programming \ Visual
Studio 2012 \ Projects \ sfml-app \ sfml-app \ ImageManager.h 10 2 sfml-app
答案 0 :(得分:37)
vector
来自std
命名空间,因此您必须使用std::
来指定:
std::vector<sf::Texture> textureList;
或者您可以使用using
声明:
using std::vector;
vector<sf::Texture> textureList;
答案 1 :(得分:5)
由于我在代码示例中没有看到任何using
语句,因此我很确定您需要在std::
声明中添加vector
,如下所示:
std::vector<sf::Texture> textureList;