So... I think this leaves a bit of room for interpretation, and I wanted to know if anybody knows what the spirit of the standard is...
class A {
const int size_;
public:
A(int size) : size_(size) {}
};
In your example:
class A {
const int size_;
This member variable is not a "constant" for the purposes of the style guide. Its value cannot be changed after construction, but is different per instance. A "constant" inside a class would be constexpr
or static const
or enum
. As it stands, it is not a constant so does not get a k
prefix.
To answer your specific questions individually:
size_
because it's not a "constant" in terms of the style guide.Finally, note that const
member variables inhibit the compiler-generated assignment operator, which is one reason you don't see them that often.