From: HarryJames
Superuser, a lot of that went over my head.
Why do you define the variables with an underscore at the start, and what is an inline (and why do you declare const twice).
Shuttleu, I was going to do that anyway but I didn't think of making them private. Thanks :)
The underscore is just there to show me that I'm using variables from the class. Otherwise (depending on IDE), i might confuse them on local ones. inline -keyword is pretty much useless nowadays, but I added it there since I've used in for the last 20 years :)
inline is a hint to the modern compilers to inject the code as it is when it's called. Compiler might do this or not - as I said, it's just a hint. Even if you don't type inline there, the compiler might inline the function still. I guarantee you, micro-optimizations are irrelevant nowadays.
The first const from
const std::string & Getname() const
tells compiler to return a reference to the class' variable. Therefore, it doesn't return copy of it but a reference instead. When you compile your code in debug mode, it doesn't matter, but there is a difference in fully optimized code.
Generally speaking, you should hide your class variables from the user. The user should only need to know how to use the class, not the little nuances and implementation details.
I highly recommend you to read
C++ faq lite. There's very good information for your disposal - including const correctness ;)