我有很多没有内联的静态成员变量的类,现在我正在重构它们。内联静态成员变量是否比它们的对应变量慢? (我读到内联METHODS对性能不利,它与VARIABLES一样吗)
我更喜欢哪个:
内联:
class AClass
{
public:
//standart data types
static inline int LastStaticIndex = 0;
static inline bool Log_AllEnabled = false;
//a struct (in microsoft case "CRITICAL_SECTION")
static inline Mutex mutex;
//a struct with member with dynamic size
static inline std::string Text = "testing";
};
没有内联:
class AClass
{
public:
//standart data types
static int LastStaticIndex;
static bool Log_AllEnabled;
//a struct (in microsoft case "CRITICAL_SECTION")
static Mutex mutex;
//a struct with member with dynamic size
static std::string Text;
};
//cpp file, (or even same header file)
int AClass::LastStaticIndex = 0;
bool AClass::Log_AllEnabled = false;
Mutex AClass::mutex = Mutex();
std::string AClass::Text = "testing";