Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7090273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:01:46+00:00 2026-05-28T08:01:46+00:00

I have two baseclasses; MemoryManagedObject and Gameobject. The idea is to have my own

  • 0

I have two baseclasses; “MemoryManagedObject” and “Gameobject”. The idea is to have my own classes inherit from “Gameobject”, which inherits from “MemoryManagedObject”.

#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

However my compiler (android-ndk, gcc 4.4.1 afaik) throws me “Undefined Reference” linker errors in functions: ~MemoryManagedObject and ~GameObject: undefined reference to MemoryManagedObject::delete(void* obj) and MemoryManagedObject::DecreaseRefCount

Why is this? I have written all the methods in .cpp files which are included in the compilation; I believe there is something wrong with how I declare the virtual destructos but I don’t know why.

EDIT: Posting the testclass and the cpp files:

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());
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:01:46+00:00Added an answer on May 28, 2026 at 8:01 am

    You are writing your virtual destructors inline, which will typically cause them to be emitted in every compilation unit, as weak symbols. In addition, since the first (and only) virtual function in your classes is the destructor, that will be the key-function, with which the vtable will emitted.

    I’d guess that these two things are interacting badly, causing inline destructors not to be included in the final link.

    In any case, the solution is to move the definition of your virtual destructors out-of-line, into the cpp file. Unless you declare instances of your objects on the stack, the desctructors will never be called except through the vtable anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Inside a DLL, we've defined two classes (Class1 and Class2) which inherit from an
Say we have a class inheriting from two base classes (multiple inheritance). Base class
There are two base classes have same function name. I want to inherit both
My NSArray holds two different types of classes, both of which derive from NSObject
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have two identical tables and need to copy rows from table to another.
I have two classes, and want to include a static instance of one class
I have two webapplication, one is a simple authenticationsite which can authenticate the logged
VB.NET 2008 .NET 3.5 I have two base classes that are MustInherit (partial). Let's
I have two UserControl classes, RequiredFields and OptionalFields . I wanted to have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.