Comment Re:Refutation (Score 1) 546
Yes, you've managed to find workarounds to all of these issues. There are of course ways to work around them. People do use C++ to get real work done; I have used it successfully many times in the past.
The point is that you have to *know* about all of these issues in order to use just this one feature effectively, without introducing subtle bugs, performance issues, or design problems.
Your solutions will mostly work of course but they are not terribly compelling. We might as well keep going:
- Calling arbitrary functions in constructors might work, but you can't return multiple values to use as different constructor arguments, so there are more hacks to be done there.
- Taking a bool& is pointless; you still need a dead-state for the destructor, so you may as well make a separate method to test for the dead-state after the constructor is run. (Good style also generally dictates you should never use non-const reference parameters; use pointers for out parameters to highlight that they will be written to.)
- Making its destructor protected prevents the class from being destroyed at all unless it is subclassed; the example GGP gave would longer work. I'm not sure what you meant be this. I do agree that documentation should suffice, but tools like -Weffc++ will still warn about it (and rightfully so.)
- I am not sure what you mean by resource classes. All I'm saying is that if MyClass contains a pointer and you forget to create a copy constructor, the compiler will do so implicitly, and your class will break horribly somewhere down the line.
Again, these are not insurmountable issues. They are just many things you need to be aware of in order to use constructors effectively. No other language has such land mines in such a simple feature as object constructors.