c – 矢量不是模板?

前端之家收集整理的这篇文章主要介绍了c – 矢量不是模板?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我目前正在尝试遵循一个关于制作自动向下RPG的简单2D瓦片引擎的教程.由于某些原因,虽然我得到智能感知错误

矢量不是模板

“矢量”一词用红色加下划线.为什么这不行?为什么它告诉我这是一个模板,为什么这个程序的意思不会奏效?

#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-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

解决方法

vector来自std命名空间,所以你必须使用std ::来指定:
std::vector<sf::Texture> textureList;

或者你可以使用一个using语句:

using std::vector;

vector<sf::Texture> textureList;

猜你在找的C&C++相关文章