C++ std::将字符串映射到指针
C++ std::map string to pointer
我目前正在将C++与 Direct3D 一起使用,并正在尝试更改我的资产存储。
现在我的资产存储为"矢量纹理列表",并使用枚举定义获得。
我想通过使用 STL map 类使类更加开放。但是,我以前从未使用过这个类,我遇到了我不理解的问题。
我刚刚将所有内容都进行了简单的测试,目前有以下内容:
#include <d3d9.h>
#include <d3dx9.h>
#include <map>
#include <string>
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")
using namespace std;
class Assets
{
private:
typedef std::map<string, IDirect3DTexture9*> TexMap;
TexMap textureList;
public:
IDirect3DTexture9* LoadTexture(IDirect3DDevice9* pd3dDevice, LPCWSTR file, string key)
{
//load a texture from file
IDirect3DTexture9* tex;
//D3DXCreateTextureFromFile(pd3dDevice, file, &tex);
D3DXCreateTextureFromFileEx(pd3dDevice, file, 512, 512, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0xFF000000, NULL, NULL, &tex);
//store the loaded texture to a vector array
textureList.insert(TexMap::value_type(key, tex));
return S_OK;
}
}
当我尝试运行它时,我收到"调试断言失败"错误,表达式为"映射/设置迭代器不兼容"
我只是觉得我已经在代码中将其简化为罐头,但查看类似示例仍然看不到错误。
我还运行了代码:
#include <d3d9.h>
#include <d3dx9.h>
#include <map>
#include <string>
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")
using namespace std;
class Assets
{
private:
typedef std::map<int, int> TexMap;
TexMap textureList;
public:
IDirect3DTexture9* LoadTexture(IDirect3DDevice9* pd3dDevice, LPCWSTR file, string key)
{
//load a texture from file
IDirect3DTexture9* tex;
//D3DXCreateTextureFromFile(pd3dDevice, file, &tex);
D3DXCreateTextureFromFileEx(pd3dDevice, file, 512, 512, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0xFF000000, NULL, NULL, &tex);
//store the loaded texture to a vector array
//textureList.push_back(tex);
textureList.insert(TexMap::value_type(3, 4));
return S_OK;
}
}
只是因为它只是使用整数,我仍然得到同样的错误。
这个错误实际上可能是非常基本的——D3DXCreateTextureFromFileEx
想要类型 IDirect3DTexture9*
作为它的最后一个参数,但你给它类型 IDirect3DTexture9**
. 也就是说,改变
D3DXCreateTextureFromFileEx(..., &tex);
自
D3DXCreateTextureFromFileEx(..., tex);
相关文章:
- 如何创建对象函数指针C++映射?
- c++:复制、删除和运算符=在原始指针映射中
- 尝试通过指针映射访问类成员
- 使用函数指针映射时的 C++ 调用函数
- 将新元素推送到函数指针映射中 "inline" ?
- 如何在C 11中创建指针映射以静态成员功能
- 方法指针映射,编译器说他们不接受任何参数
- 从指针映射调用函数,指向具有可变数量参数的函数
- 如何使用boost::与函数指针映射正确绑定
- std::按值或指针映射操作
- 将函数指针映射到 std::string
- 指向指针向量的指针映射的错误
- 使用C++中的函数指针映射枚举键和值
- 创建指向成员函数的指针映射
- 无法从指向多态类的指针映射获取有效的指针
- C++ - 通过 getter 函数在单独的类中从对象指针映射访问成员函数
- 指向成员函数的指针映射:无法将 void (*) 转换为 void (对象::*)
- std::基类指针映射
- 为对象指针映射编写函数模板时出现问题
- 指针映射的数组下标运算符