0

I've seen a lot of times in c++ libraries tones of objects whose names start with underscores. I know some cases when this is useful for example:

    class Person {
    private: 
       unsigned int age;
       //...
    public:
       Person(unsigned int _age): age(_age) {}
    };

here it's useful to distinguish logically same objects _age, age.

But there are also cases when global functions names (not from a class) also have single or multiple underscores. So I would like to understand this in general and more ideologically.

So:

What are the benefits for this kind of naming ?

When it's need to use single and when multiple underscores at the start ?

ampawd
  • 968
  • 8
  • 26
  • Double underscores are usually reserved for compiler's internal use as a convention. Single underscores are reserved for library functions to prevent collisions. – Parag Agarwal Jun 10 '16 at 12:07
  • In this specific case, `Person(unsigned int age):age(age){}` would be legal as well (and produce the same code). – IInspectable Jun 10 '16 at 12:11
  • @ParagAgarwal - double underscores are **always** reserved, not sometimes. – Pete Becker Jun 10 '16 at 12:24

1 Answers1

0

There's never a requirement to use an initial single or a double-underline prefix to variable names.

This is simply someone's naming convention, or a habit.

Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148