The term auto-magic is Stroustrup's, not mine. |
No worries :+) I wasn't trying to attribute it to you, it was inside a quote.
The implication to me was that despite his code snippet which covers the point you initially raised, ..... |
Well I don't think it does cover the point I raised: the example is specifically to do with a constructor; I meant in general.
.... he seems to be saying that the action covered by it is done behind the scenes |
Yes it is. But as I understand it, it doesn't apply outside of a constructor.
I was hesitant about the constructor aspect too before I posted but on reflection, but without checking, I don't think it matters whether a class of some sort or a simple ol' new char, new int etc was involved.
|
Theoretically it does matter whether it is a class or not. But if new fails for a char or int, then I guess one has bigger problems :+D. But the point was to not use new or delete
ever.
However that is tempered in my mind when some poor bugger is faced with more basic constraints from school etc and someone saying don't use new/delete doesn't get marks in semeseter 1 as you probably know. |
Yes well that is a problem, people still teach
new
/
delete
, along with
using namespace std;
Why can't they teach it properly? Maybe partially because they are too scared to update their syllabus to C++11? Why teach them
new
when they are going to have to abandon it as soon as they start work? Hopefully earlier. Some schools still insist on C++03 code, so by February next year with C++17, they will be 14 years and 3 versions of the standard behind.
But you are right, if some student makes use of
std::unique_ptr
, their teacher is bound to ask where they learned that from. I just wish that teachers would accept that something valid has been learnt from elsewhere.
With the constraints from the schools, I think we (cplusplus respondents) are sometimes at cross purposes with the teachers here. Using things like
std::vector
instead of arrays is a solid technique that differentiates C++ from C, but the teachers want the students to learn all the different aspects. Same story with pointers. Part of the trouble there is the big difference between C and C++, courses are often a combination of the two.
Anyway all of this is off topic, but I hope there has been a little bit of education all round - me included :+)