Identical class member names and argument argument names in C ++

I have a simple object that contains some [public] data.

I want my interface to be clean, so I don’t want to pre / post-fix anything by the names of public variables or the argument names of my function.

However, I ended up doing something like this:

template<typename T> struct Foo
{
  explicit Foo(T x) : x(x) // This [i.e., x(x)] seems to be doing the "Right Thing", but is this well defined?
  {/*            ^ 
       No pre-/post- fixing.
   */
  }

  T x; // No pre-/post- fixing.
};

Just to repeat: all I ask is how well defined it is. Should I not do this or should not do this ...

Thank.

+3
source share
2 answers

Yes, that’s fine, and completely standard.

, x(...) , , - [edit: ].

, :

explicit Foo(T x)
{
    this->x = x;
}
+6

, ctor - , .

. , "" - , ctor, . ctor - "" ctor.

+1

Source: https://habr.com/ru/post/1730957/


All Articles