次のコードは 100% 正しいですか? 私はゲームをコーディングしており、パワーなどの情報CItemElem
を保持するクラスです。アイテムからのポインタを という名前の別のクラスのインスタンスに格納したいと考えています。ご覧ください:Item
CChatLink
[.H]
#pragma once
class CChatLink
{
private:
CChatLink(){}; //no new usage or global object allowed
~CChatLink(){};
public:
BOOL InsertChatLink( TCHAR* szText, CItemElem *pItemElem );
map<std::string,CItemElem*>m_mChatLink;
static CChatLink* GetInstance( void )
{
static CChatLink pObj;
return &pObj;
}
};
[.cpp]
#include "StdAfx.h"
#include "Item.h"
#include "CChatLink.h"
BOOL CChatLink::InsertChatLink( TCHAR *szText, CItemElem* pItemElem )
{
if( pItemElem && szText )
{
std::string szInsert( szText );
CItemElem *pItem = new CItemElem; //as far as I know, it must be allocated on the heap to be inserted ^^
pItem = pItemElem;
m_mChatLink.insert( make_pair( szInsert, pItem ) );
return TRUE;
}
return FALSE;
}
std::string
そのまま収納できますmap
か?
(現在C++を勉強中なのでお手柔らかにお願いします。)