簡體   English   中英

C ++ std :: map指向指針的字符串

[英]C++ std::map string to pointer

我目前將C ++與Direct3D結合使用,並試圖更改我的資產存儲。

現在,我的資產存儲為“ vector textureList”,並使用枚舉定義獲得。

我想通過使用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;
}
}

只是它只是使用ints而我仍然遇到相同的錯誤。

該錯誤實際上可能是非常基本的D3DXCreateTextureFromFileEx希望將IDirect3DTexture9*作為其最后一個參數,但是您將其賦予IDirect3DTexture9**類型。 也就是說,改變

D3DXCreateTextureFromFileEx(..., &tex);

D3DXCreateTextureFromFileEx(..., tex);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM