Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualThe King2

Posted 04 April 2013 - 08:20 AM

Hello,

 

so I've defined an interface for my renderer like this:

 

#pragma once
#include "ITexture.h"
#include "IFontWriter.h"
#include "ISprite.h"
#include <string>

class IGfx2D
{
public:

	virtual void SetClipRect(const Rect* pClipRect) = 0;
	virtual void SetRenderTarget(UINT id, const ITexture* pTexture) = 0;
	virtual void SetCursor(int offX, int offY, std::wstring sFileName) = 0;

	virtual void ClearTexture(const ITexture& texture) = 0;

	virtual void Begin(void) = 0;
	virtual void End(void) = 0;
};

From this I derive a class with a custom destructor, this destructor never gets called, unless I add an "virtual ~IGfx2D(void) {};" destructor to the interface. Why? This happens to all my (pure) virtual classes without a custom destructor. I assume the compiler (VS 2012) does automatically add a standard destructor if I didn't define one myself. But I though an interface should not have an destructor. Does an interface in c++ really need an virtual destructor or is it some compiler-setting or define I need to do?


#1The King2

Posted 04 April 2013 - 08:19 AM

Hello,

 

so I've defined an interface for my renderer like this:

 

#pragma once
#include "ITexture.h"
#include "IFontWriter.h"
#include "ISprite.h"
#include <string>

class IGfx2D
{
public:

	virtual void SetClipRect(const Rect* pClipRect) = 0;
	virtual void SetRenderTarget(UINT id, const ITexture* pTexture) = 0;
	virtual void SetCursor(int offX, int offY, std::wstring sFileName) = 0;

	virtual void ClearTexture(const ITexture& texture) = 0;

	virtual void Begin(void) = 0;
	virtual void End(void) = 0;
};

From this with a custom destructor, this destructor never gets called, unless I add an "virtual ~IGfx2D(void) {};" destructor to the interface. Why? I assume the compiler (VS 2012) does automatically add a standard destructor if I didn't define one myself. But I though an interface should not have an destructor. Does an interface in c++ really need an virtual destructor or is it some compiler-setting or define I need to do?


PARTNERS