This was more of a conceptual question, but I'll provide a particular instance where I'm wondering about this. If I have a class that has several objects as properties, is it better to allocate them statically within the class, or dynamically during construction? For example, I have the following class (unecessary code emitted)
class OutlinedText
{
protected:
sf::Text BaseText;
sf::Text BackgroundText;
}
sf::Text are both objects as well. My question is, is it better to have them as declared above, and initialize them as follows
OutlinedText::OutlinedText(std::string &text, sf::Color MainColor, sf::Color OffsetColor, sf::Font &font, sf::Vector2f Pos, unsigned int BaseFontSize, unsigned int BackFontSize, float Offset)
{
BaseText = sf::Text(text, font, BaseFontSize);
BaseText.SetColor(MainColor);
BackgroundText = sf::Text(text, font, BackFontSize);
BackgroundText.SetColor(OffsetColor);
}
or, should i have them as pointers and allocate them with new as follows:
BaseText = new sf::Text(text, font, BaseFontSize);
BaseText->SetColor(MainColor);
and deallocate them with delete in the destructor? I know the stack allocates memory alot faster, but I think I'm double initializing the way I have now. SO is it a case by case thing or is one always better then the other? I'm still used to the C# way of doing things, so I was curious what the proper way to do this for C++ is. If I have a fundamental misunderstanding, please correct me.
Thanks in advance