Boost logo

Boost Users :

From: Alan M. Carroll (amc_at_[hidden])
Date: 2008-07-21 12:09:20


At 06:21 AM 7/21/2008, Richard Dingwall wrote:
Not a prefix, but a a trailing underscore suffix is generally used
(identifiers starting with an underscore are reserved for the
compiler).

class foo
{
public:
        int bar() const { return bar_; }
private:
        int bar_;
};

According to various language references [1][2][3] the C++ specification says

"Each name that contains a double underscore _ _ or begins with an underscore followed by an uppercase letter
(
2.11 ) is reserved to the implementation for any use.
— Each name that begins with an underscore is reserved to the implementation for use as a name in the global
namespace"

which means that member variables of the form "_bar" are legal C++.

[1] http://msdn.microsoft.com/en-us/library/565w213d.aspx
[2] http://publib.boulder.ibm.com/infocenter/compbgpl/v9v111/index.jsp?topic=/com.ibm.xlcpp9.bg.doc/language_ref/ident.htm
[3] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2691.pdf, 17.4.3.2.2

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net