From 83fd5df368cabc97d6607ad81f8ffb046c66c05c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 28 May 2012 14:34:16 +0200 Subject: [PATCH] Disable instantiation of all Abstract* classes. For classes which already have pure virtual functions instantiation is not allowed, but for other there needs to be at least one pure virtual method: the destructor. Pure virtual functions actually can have implementations, but they must be called explicitly. Destructors are called explicitly, so for them it works. --- src/AbstractImage.h | 4 +++- src/AbstractShaderProgram.h | 4 +++- src/AbstractTexture.h | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/AbstractImage.h b/src/AbstractImage.h index 2d9c966ae..aad37c9c0 100644 --- a/src/AbstractImage.h +++ b/src/AbstractImage.h @@ -216,7 +216,7 @@ class MAGNUM_EXPORT AbstractImage { inline AbstractImage(Components components, ComponentType type): _components(components), _type(type) {} /** @brief Destructor */ - inline virtual ~AbstractImage() {} + virtual ~AbstractImage() = 0; /** @brief Color components */ inline Components components() const { return _components; } @@ -229,6 +229,8 @@ class MAGNUM_EXPORT AbstractImage { ComponentType _type; /**< @brief Data type */ }; +inline AbstractImage::~AbstractImage() {} + } #endif diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 3be60d690..9512cca73 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -121,7 +121,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * * Deletes associated OpenGL shader program. */ - inline ~AbstractShaderProgram() { glDeleteProgram(program); } + virtual ~AbstractShaderProgram() = 0; /** * @brief Use shader @@ -300,6 +300,8 @@ class MAGNUM_EXPORT AbstractShaderProgram { State state; }; +inline AbstractShaderProgram::~AbstractShaderProgram() { glDeleteProgram(program); } + } #endif diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index df2e025d2..319d84adf 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -472,9 +472,7 @@ class MAGNUM_EXPORT AbstractTexture { * * Deletes assigned OpenGL texture. */ - inline virtual ~AbstractTexture() { - glDeleteTextures(1, &texture); - } + virtual ~AbstractTexture() = 0; /** @brief %Texture layer */ inline GLint layer() const { return _layer; } @@ -568,6 +566,8 @@ class MAGNUM_EXPORT AbstractTexture { GLuint texture; }; +inline AbstractTexture::~AbstractTexture() { glDeleteTextures(1, &texture); } + /** @relates AbstractTexture @brief Convertor of component count and data type to InternalFormat */