我有一個關於提供自定義刪除方法boost::shared_ptr
構造函數的問題。自定義刪除提升shared_ptr
例如,我有一個GameObjectFactory
類創建/銷燬GameObjects
。它有一個MemoryManager
的實例,它可以是Allocate()/Deallocate()
的內存。 CreateObject()
返回GameObject
,通過MemoryManager
分配,封裝在boost::shared_ptr
中。
當boost::shared_ptr
破壞時,它應該調用我的MemoryManager->Deallocate()
方法。然而,我不能正確的解決問題。我得到這些錯誤:
error C2276: '&' : illegal operation on bound member function expression
error C2661: 'boost::shared_ptr<T>::shared_ptr' : no overloaded function takes 2 arguments
我已閱讀提升文檔和我從計算器得到了命中率,但我無法得到它的權利。我不明白爲什麼下面的dosnt工作。
這是我的代碼;
#ifndef _I_GAMEOBJECT_MANAGER_H
#define _I_GAMEOBJECT_MANAGER_H
#include "../../Thirdparty/boost_1_49_0/boost/smart_ptr/shared_ptr.hpp"
#include "EngineDefs.h"
#include "IMemoryManager.h"
#include "../Include/Core/GameObject/GameObject.h"
namespace Engine
{
class IGameObjectFactory
{
public:
virtual ~IGameObjectFactory() { }
virtual int32_t Init() = 0;
virtual bool Destroy() = 0;
virtual bool Start() = 0;
virtual bool Stop() = 0;
virtual bool isRunning() = 0;
virtual void Tick() = 0;
template <class T>
inline boost::shared_ptr<T> CreateObject()
{
boost::shared_ptr<T> ptr((T*) mMemoryMgr->Allocate(sizeof(T)),&mMemoryMgr->Deallocate);
return ptr;
}
template <class T>
inline boost::shared_ptr<T> CreateObject(bool UseMemoryPool)
{
boost::shared_ptr<T> ptr((T*) mMemoryMgr->Allocate(sizeof(T),UseMemoryPool), &mMemoryMgr->Deallocate);
return ptr;
}
protected:
IMemoryManager* mMemoryMgr;
};
}
#endif
我仍然得到以下錯誤:錯誤C2661:'boost :: shared_ptr :: shared_ptr':沒有重載的函數需要2個參數使用最新的boost版本 –
KaiserJohaan
2012-03-31 19:03:54
@KaiserJohaan:那麼,你使用的是什麼版本的Boost? – 2012-03-31 19:07:14
我正在使用boost 1.49.0 – KaiserJohaan 2012-03-31 19:12:15