I am new to using templates.
Is it appropriate to make a template class using constructor overloading for the various actual types?
For example:
template <typename T>
class A
{
A(..will receive paramaters for a specific type T);
A(..will receive DIFFERENT params for a different type T);
}
The code will compile because all functionality for each instantiation works, however logically (and practically) speaking, each constructor will be called depending on the type that I am actually using.
This suits my purpose well, but is this a correct "programming mindset"?
To be more specific - using SFML, here is what I am referring to, one will be a sprite and the other a shape, but with common functionality but exclusive too, such as the setColor or setTexture functions. What I mean is there will be no logical sense in calling the second constructor for T as a sprite:
template <typename T>
class GameObject {
public:
GameObject(sf::Texture& texture, sf::Vector2f pos)
{
m_drawable.setTexture(texture);
m_drawable.setOrigin(m_drawable.getGlobalBounds().width / 2, m_drawable.getGlobalBounds().height / 2);
m_drawable.setPosition(pos);
}
GameObject(sf::Color color, sf::Vector2f pos)
{
m_drawable.setColor(color);
m_drawable.setPosition(pos);
}
private:
T m_drawable;
};