0

What is the meaning of the underscore in template prototyping? That is the example of template:

template<typename _Tp> _Tp* Mat::ptr(int i=0)

Why people add underscore before Tp?

user0042
  • 7,917
  • 3
  • 24
  • 39
syuntoku14
  • 19
  • 1
  • 2
    Symbols beginning with a `_` are reserved for standard and compiler internal implementations. – user0042 Dec 30 '17 at 09:47
  • 3
    "People" have probably looked at the standard library implementation, where the code often uses reserved names like `_Ty` to avoid collisions with user code. And then the user code starts to *also* use these names. Don't do that! – Bo Persson Dec 30 '17 at 09:52
  • 1
    If it is third-party code (which the name `Mat::ptr` implies), it means the developer doesn't really know what they are doing. Such identifiers, in any scope, are reserved for use by the implementation - for example, as macro names. Since there may be a clash with the implementation (e.g. macros used in the standard library, or compiler-specific features) the behaviour is undefined. If this sort of code is used WITHIN the implementation (e.g. standard headers, compiler intrinsics, etc) ... well, that's what these things are for. – Peter Dec 30 '17 at 09:54
  • 2
    names begining by 1 underscore folowed by a capital letter, declared at global namespace scope are reserved (not all names begining by a single underscore) – Oliv Dec 30 '17 at 10:08
  • 1
    @Oliv -- "Each name that begins with an underscore is reserved to the implementation for use as a name **in the global namespace**." [global.names]/1 (emphasis added). In addition, names that begin with an underscore followed by a capital letter are reserved **for any use** (as are names that contain two consecutive underscores). – Pete Becker Dec 30 '17 at 13:32

0 Answers0