I am using SFML and have a class like the following:
#include <SFML\Graphics.hpp>
class Overlay
{
public:
Overlay(int width, int height);
Overlay(const sf::Texture*);
Overlay(const sf::Sprite*);
~Overlay();
private:
sf::Texture _texture;
sf::Image _img;
};
Now the following constructor for Overlay(const sf::Sprite*)
is working:
Overlay::Overlay(const sf::Sprite* spr) {
int width = spr->getTexture()->getSize().x;
int height = spr->getTexture()->getSize().y;
_texture.create(width, height);
_img.create(width, height, sf::Color::Transparent);
}
However, the following, nested constructors are not:
Overlay::Overlay(int width, int height)
{
_texture.create(width, height);
_img.create(width, height, sf::Color::Transparent);
}
Overlay::Overlay(const sf::Texture* tex) {
sf::Vector2u textureSize = tex->getSize();
Overlay(textureSize.x, textureSize.y);
}
Overlay::Overlay(const sf::Sprite* spr) {
Overlay(spr->getTexture());
}
To me it looks, like the two snippets should be doing the same thing if the following is executed:
sf::Sprite image;
Overlay mOverlay(&image);
Although both of them compile just fine, when the second code snippet (nested constructors) is called, _img
ends up having a size of 0 and its m_pixels
array is empty.