Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • I like this answer it acknowledges that the real world isn't always the ideal world. But from curiosity, how could I possibly accidentally call a constructor? Commented Mar 9, 2017 at 22:03
  • @Airhead one example is implicit conversions, like for function calls: ideone.com/jTfzsB. Since constructors are implicit by default, calling a function with a type that is implicitly convertible to the expected type through a single parameter constructor, will call the constructor. Commented Mar 9, 2017 at 23:17
  • Okay, so if I mark the constructor as explicit, then I should avoid this problem, no? Any other situations? Not being snarky, genuinely curious. Commented Mar 9, 2017 at 23:20
  • 3
    I heavily disagree that "beeing new C++" is a valid reason for not "doing big work in a constructor". I also disagree that "big work in a constructor" for the case described in the question has a risk of "trapping users in a corner." That sounds all very superstitious. Commented Mar 10, 2017 at 6:43
  • 2
    @Airhead: "implicit conversion" for your case would mean the constructor gets called implicitly and gets a file name out of thin air? I think that is quite unlikely ;-) Commented Mar 10, 2017 at 6:54