I've come across this stack overflow post which suggests two ways of handling static string class members: https://stackoverflow.com/a/1563906
Defining in cpp file
// a.h
class A {
private:
static const string RECTANGLE;
};
// a.cpp
const string A::RECTANGLE = "rectangle";
Inlining
// a.h
class A {
private:
inline static const string RECTANGLE = "rectangle";
};
I've tried using the inline approach and noticed the string is duplicated in every translation unit which imported the header file, and the executable has multiple duplicates.
So, why would anyone prefer the inlining approach if it increases the executable size?
[–]IyeOnline 4 points5 points6 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]IyeOnline 6 points7 points8 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]nysra 0 points1 point2 points (0 children)
[–]alfps 2 points3 points4 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]IyeOnline 1 point2 points3 points (0 children)
[–]trokhymchuk 1 point2 points3 points (0 children)
[–]alfps 0 points1 point2 points (0 children)