0

In C++, there are a couple ways to make constructors - with the Member Initialization List (MIL), with this->field1 = 1, or by just doing field1 = 1.

Which is the best way to construct a structure, when is it ideal to use these three methods??

I'm most curious about the difference between this->field1 and field1, do they not refer to the same field in a structure?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
ming
  • 229
  • 1
  • 9
  • 2
    MIL always when it's possible. The latter two are equivalent (except for some specific template contexts) – Yksisarvinen Nov 02 '19 at 21:37
  • 1
    The member intializer list does not do the same thing as the other two methods, but if you limit this question to the two other cases, [this question](https://stackoverflow.com/questions/993352/when-should-i-make-explicit-use-of-the-this-pointer) is a duplicate. – walnut Nov 02 '19 at 21:41
  • 1
    Possible dupes: [Why should I prefer to use member initialization list?](https://stackoverflow.com/questions/926752/why-should-i-prefer-to-use-member-initialization-list), [Should I use `this` within a class?](https://stackoverflow.com/questions/9590820/should-i-use-this-within-a-class) – Yksisarvinen Nov 02 '19 at 21:42
  • There does seem to be two separate questions here (which might be not obvious to someone asking this), so I've added a second question to the "potential duplicate" list. – JaMiT Nov 02 '19 at 22:05

0 Answers0