【发布时间】:2018-03-25 01:34:24
【问题描述】:
我正在使用 SDL2 库来创建游戏。我将加载的 SDL_Textures 存储到此 map 容器中:
std::map<const SDL_Texture, std::vector<int[3]>> textures;
地图的键是SDL_Texture本身。 值是一个x,y,z坐标的向量,代表所有渲染纹理的地方。
当我尝试将 std::pair 插入到结构中时,会出现问题,如下所示:
textures.insert(
std::pair<const SDL_Texture, std::vector<int[3]>>(
SDL_CreateTextureFromSurface(renderer, s),
std::vector<int[3]>()
)
);
其中 renderer 是 SDL_Renderer,s 是 SDL_Surface。 Visual Studio 2017 的 IDE 将其标记为不正确:
no instance of constructor "std::pair<_Ty1,_Ty2>::pair
[with _ty1=const SDL_Texture, _Ty2=std::vector<int[3],std::allocator<int[3]>>]"
matches the argument list argument types are:
(SDL_Texture*, std::vector<int[3],std::allocator<int[3]>>)
它显然不知道如何构造 std::pair,但我不知道为什么,因为我能够在 for 循环中构造一个没有错误:
for (std::pair<const SDL_Texture, std::vector<int[3]>> tex : textures) {
}
我认为这与我作为值插入的未初始化std::vector有关。是这个原因吗?如果是这样,是否有解决方法?如果不是,可能是什么问题?
另外,有没有更好的方法来做我想做的事情?我要追求速度。
【问题讨论】:
标签: c++ insert containers sdl-2 stdmap