【发布时间】:2015-04-28 14:55:04
【问题描述】:
我收到了错误
" src/Graphics.cpp:29:32: erreur: '->' 的基本操作数具有非指针类型'std::vector' "
关于以下代码:
构造函数:
Graphics::Graphics()
{
this->app = new sf::RenderWindow(sf::VideoMode(800, 800, 32), "La Zapette !",
sf::Style::Close | sf::Style::Titlebar);
sf::Image img;
img.LoadFromFile("./res/grass.jpg");
for (int i = 0; i != 16; i++)
{
this->map.push_back(new sf::Sprite());
this->map.back()->SetImage(img);
this->map.back()->SetPosition(sf::Vector2f(0, 50 * i));
this->app->Draw(this->map->back());
}
this->app->Display();
}
类:
class Graphics
{
private:
sf::RenderWindow *app;
std::vector<sf::Sprite*> map;
public:
Graphics();
~Graphics();
Event getEvent();
};
当我在 .back() 方法后面放一个点而不是一个箭头时,它不会编译。
谢谢
【问题讨论】:
-
下次遇到编译器错误时,请指出您发布的代码中哪一行与错误相对应。例如,我猜第 29 行对应于
this->app->Draw(this->map->back());?但是,既然你已经知道了,我为什么还要猜测呢?
标签: c++ pointers dereference