我有一个关于为
例如,我有一个
当
我已经阅读了Boost文档和来自stackoverflow的相关内容,但是我仍然无法理解。我不明白为什么以下代码不能正常工作。
下面是我的代码:
boost::shared_ptr
构造函数提供自定义删除方法的问题。例如,我有一个
GameObjectFactory
类,它创建/销毁GameObjects
。它拥有一个MemoryManager
实例,可以Allocate()/Deallocate()
内存。通过MemoryManager
分配的GameObject
通过boost::shared_ptr
封装并返回CreateObject()
。当
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
我已经阅读了Boost文档和来自stackoverflow的相关内容,但是我仍然无法理解。我不明白为什么以下代码不能正常工作。
下面是我的代码:
#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