私は2つのベースクリップを持っています。 "MemoryManagedObject"と "GameObject"があります。私のクラスは、 "MemoryManagedObject"を継承した "Gameobject"から継承することが考えられます。複数のベースラインを使用するとリンクエラーが発生する
#ifndef _GAME_OBJECT_H
#define _GAME_OBJECT_H
#include "MemoryManagedObject.h"
class GameObject : public MemoryManagedObject
{
public:
GameObject() { }
GameObject(bool UseMemPool): MemoryManagedObject(UseMemPool) { }
virtual ~GameObject() { }
long GetGameObjectID();
protected:
long mGameObjectID;
};
inline long GameObject::GetGameObjectID()
{
return mGameObjectID;
}
#endif
#ifndef _MEMORY_MANAGED_OBJECT_H
#define _MEMORY_MANAGED_OBJECT_H
#include <new>
class MemoryManagedObject
{
public:
MemoryManagedObject();
MemoryManagedObject(bool UseMemPool);
virtual ~MemoryManagedObject() { DecreaseRefCount(); }
bool IsAllocatedWithMemPool();
void* operator new(size_t size);
void* operator new(size_t size, bool UseMemPool);
void operator delete(void* obj);
long GetRefCount();
private:
void IncreaseRefCount();
void DecreaseRefCount();
long mRefCount;
bool mAllocatedWithMemPool;
};
#endif
しかし、私のコンパイラ(アンドロイド - NDK、GCC 4.4.1私の知る限りでは)機能で私 "未定義リファレンス" リンカエラーがスローされます〜MemoryManagedObjectとは〜ゲームオブジェクト:MemoryManagedObjectへの未定義の参照は::削除(無効* OBJ)とMemoryManagedObject :: DecreaseRefCount
これはなぜですか?コンパイルに含まれる.cppファイルにすべてのメソッドを書きました。仮想デストラクトを宣言する方法に何か問題があると私は信じていますが、理由はわかりません。
EDIT:TestClassをとのcppファイルを投稿:
TestClass1.h
#ifndef _TEST_CLASS_1_H
#define _TEST_CLASS_1_H
#include "GameObject.h"
class TestClass1 : public GameObject
{
public:
TestClass1();
TestClass1(bool UseMemPool);
~TestClass1();
void TestMe();
};
TestClass1.cpp
#include "TestClass1.h"
TestClass1::TestClass1()
{
}
TestClass1::TestClass1(bool UseMemPool): GameObject(UseMemPool)
{
}
TestClass1::~TestClass1()
{
}
void TestClass1::TestMe()
{
}
#endif
GameObject.cpp
#include "GameObject.h"
GameObject::GameObject()
{
}
GameObject::GameObject(bool UseMemPool): MemoryManagedObject(UseMemPool)
{
}
GameObject::~GameObject()
{
MemoryManagedObject.cpp
#include "MemoryManagedObject.h"
#include "Engine.h"
#include <stdint.h>
MemoryManagedObject::MemoryManagedObject()
{
mAllocatedWithMemPool = false;
IncreaseRefCount();
}
MemoryManagedObject::MemoryManagedObject(bool UseMemPool)
{
mAllocatedWithMemPool = UseMemPool;
IncreaseRefCount();
}
MemoryManagedObject::~MemoryManagedObject()
{
DecreaseRefCount();
}
long MemoryManagedObject::GetRefCount()
{
return mRefCount;
}
void MemoryManagedObject::IncreaseRefCount()
{
mRefCount++;
}
void MemoryManagedObject::DecreaseRefCount()
{
mRefCount--;
if (mRefCount <= 0)
{
delete this;
}
}
bool MemoryManagedObject::IsAllocatedWithMemPool()
{
return mAllocatedWithMemPool;
}
void* MemoryManagedObject::operator new(size_t size)
{
Engine* engine = Engine::GetEngine();
void* alloc;
alloc = engine->GetMemoryManager()->Allocate(size);
return alloc;
}
void* MemoryManagedObject::operator new(size_t size, bool UseMemPool)
{
Engine* engine = Engine::GetEngine();
void* alloc;
alloc = engine->GetMemoryManager()->Allocate(size, UseMemPool);
return alloc;
}
void MemoryManagedObject::operator delete(void* obj)
{
Engine* engine = Engine::GetEngine();
MemoryManagedObject* memObj = (MemoryManagedObject*)obj;
engine->GetMemoryManager()->Deallocate(obj,memObj->IsAllocatedWithMemPool());
}
}
.cppファイルを表示します。 –
宣言には何も問題はありませんが、おそらく定義には間違いはありません。問題は、私たちが見たことのないコードにあります。 –