defining an interface (solved)
Posted: Tue Jun 21, 2011 12:35 am
Hey guys,
I have a non-obvious to me question for anyone. I'm trying to inherit form an abstract base class, here's an example of the scenario I'm currently trying to wrap my head around:
AbstractMemoryPool.h
ParticleMemoryPool.h
ParticleMemoryPool.cpp
As you can see I provided no implementation for abstractMemoryPool (no .cpp file), just the .h (interface) file.
However noting the virtual destructor
This causes no linker problems. However replacing the destructors definition with either of
This and
ends up in linker issues bitching about the missing implementation of AbstractMemoryPool::~AbstractMemoryPool(void).
Of course theres no implementation of the destructor, I just want to define an interface in AbstractMemoryPool.h.
Why if I do not provide an inline body for the virtual destructor of AbstractMemoryPool does the linker bitch?
I explicitely override the virtual destructor in ParticleMemoryPool.cpp
I have a non-obvious to me question for anyone. I'm trying to inherit form an abstract base class, here's an example of the scenario I'm currently trying to wrap my head around:
AbstractMemoryPool.h
Code: Select all
#ifndef _ABSTRACTMEMORYPOOL_H_
#define _ABSTRACTMEMORYPOOL_H_
class AbstractMemoryPool
{
public:
virtual ~AbstractMemoryPool() { int j = 5; };
virtual void whatevs() = 0;
};
#endif
Code: Select all
#ifndef _PARTICLEMEMORYPOOL_H_
#define _PARTICLEMEMORYPOOL_H_
#include "AbstractMemoryPool.h"
class ParticleMemoryPool : public AbstractMemoryPool
{
public:
ParticleMemoryPool(void);
virtual ~ParticleMemoryPool(void);
virtual void whatevs();
};
#endif
Code: Select all
#include "ParticleMemoryPool.h"
ParticleMemoryPool::ParticleMemoryPool(void)
{
}
ParticleMemoryPool::~ParticleMemoryPool(void)
{
}
void ParticleMemoryPool::whatevs()
{
}
However noting the virtual destructor
Code: Select all
virtual ~AbstractMemoryPool() { int j = 5; };
This
Code: Select all
virtual ~AbstractMemoryPool();
Code: Select all
virtual ~AbstractMemoryPool() = 0;
Of course theres no implementation of the destructor, I just want to define an interface in AbstractMemoryPool.h.
Why if I do not provide an inline body for the virtual destructor of AbstractMemoryPool does the linker bitch?
I explicitely override the virtual destructor in ParticleMemoryPool.cpp