I have been quite interested in what is considered "good practice" and "bad
practice" in C++ for a little while now. I've read and read, and have concluded
that some "standards" for what is considered good programming and bad
programming are be de-facto standards (code formatting, cleanliness, etc).
Heck, to be completely honest, I'm still a little fuzzy to what good
programming is. Anyways, to my actual question: if I have an extern object of a
class, and I only want to have one object of that class instantiated throughout
the whole program, is it a good idea to make all the member variables static? I
mean, I wont be instantiating another object of said class, so why not make all
variables static? I tell myself this, but then at the same time, I also think
if I'm only going to have one class object instantiated thruoghout the entirety
of the program, does it really matter? Is it one of those "doesn't really
matter" type things?
For example, this is a very underdeveloped class of a an asset manager for a 2D
rpg game that I'll be making... I only need one object of the class instantied,
and I'll make that object an extern object. But to make the variables all
static?... Would it be good programming, bad programmin, or for this case, will
it simply not matter?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#pragma once
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <map>
namespace fg {
/* ----------------------------------------------------------------------------
* ENUM CLASS:
*
* DESCRIPTION:
* Enum class for key use with std::map.
* --------------------------------------------------------------------------*/
enum class textureKey {
};
/* ----------------------------------------------------------------------------
* CLASS:
* assets class...
* DESCRIPTION:
* Class that holds all assets. It will only have one object instantiated.
* --------------------------------------------------------------------------*/
class assets {
public:
assets();
std::string _getTextStr(textureKey&) const;
private:
static std::map<textureKey, std::string> _textureStr;
};
/* ----------------------------------------------------------------------------
* Declare extern here
* --------------------------------------------------------------------------*/
extern assets aObj;
}
|