> The move constructor is the important bit. Its presence tells C++ that this class can not be copied, only moved Is that true? I thought move ctor enabled move semantics, but if you pass by value the copy ctor was still called (except in places where RVO makes sense). And I thought to disable copying you made the copy ctor = delete.
Modern C++ for C Programmers: part 5
11–20 of 82 posts
Re: Modern C++ for C Programmers: part 5
#12> The move constructor is the important bit. Its presence tells C++ that this class can not be copied, only moved Is that true? I thought move ctor enabled move semantics, but if you pass by value the copy ctor was still called (except in places where RVO makes sense). And I thought to disable copying you made the copy ctor = delete.
So if you define a move constructor and still want your class to have a copy constructor, you'll have to explicitly define the copy constructor, too.
Re: Modern C++ for C Programmers: part 5
#13is there a modern C++ for python programmers? i have ~5 years programming in dynamic/interpreted (python/js) and compiled/gc'd(java/go) languages and i'd like to learn a systems language. i'm reading the rust programming book (and it's really good/easy to grok) but i'd also like to learn C++. the problem is that most books are either too easy (C++ as your first language) or too hard (straight into RAII and templates)…
Re: Modern C++ for C Programmers: part 5
#14> The move constructor is the important bit. Its presence tells C++ that this class can not be copied, only moved Is that true? I thought move ctor enabled move semantics, but if you pass by value the copy ctor was still called (except in places where RVO makes sense). And I thought to disable copying you made the copy ctor = delete.
(author here), it is true, try it. Sample code is on https://github.com/ahupowerdns/hello-cpp/blob/master/move.cc
Re: Modern C++ for C Programmers: part 5
#15> The move constructor is the important bit. Its presence tells C++ that this class can not be copied, only moved Is that true? I thought move ctor enabled move semantics, but if you pass by value the copy ctor was still called (except in places where RVO makes sense). And I thought to disable copying you made the copy ctor = delete.
The implicitly-declared copy constructor is deleted if there is a user-defined move constructor. See: https://en.cppreference.com/w/cpp/language/copy_constructor#... So if you define a move constructor and still want your class to have a copy constructor, you'll have to explicitly define the copy constructor, too.
Re: Modern C++ for C Programmers: part 5
#16Please please please can we get rid of headers and have modules? I find it super annoying having to specify things half in one place and half in another. Unfortunately, there still seems to be a bit of disagreement on the implementation among the standards committee.
Re: Modern C++ for C Programmers: part 5
#17> The move constructor is the important bit. Its presence tells C++ that this class can not be copied, only moved Is that true? I thought move ctor enabled move semantics, but if you pass by value the copy ctor was still called (except in places where RVO makes sense). And I thought to disable copying you made the copy ctor = delete.
https://en.cppreference.com/w/cpp/language/copy_constructor
But there's no harm in explicitly deleting it, and it helps document the intent.
Re: Modern C++ for C Programmers: part 5
#18Please please please can we get rid of headers and have modules? I find it super annoying having to specify things half in one place and half in another. Unfortunately, there still seems to be a bit of disagreement on the implementation among the standards committee.
Re: Modern C++ for C Programmers: part 5
#19is there a modern C++ for python programmers? i have ~5 years programming in dynamic/interpreted (python/js) and compiled/gc'd(java/go) languages and i'd like to learn a systems language. i'm reading the rust programming book (and it's really good/easy to grok) but i'd also like to learn C++. the problem is that most books are either too easy (C++ as your first language) or too hard (straight into RAII and templates)…
Have you tried "A Tour of C++"? https://www.safaribooksonline.com/library/view/a-tour-of/978...
Re: Modern C++ for C Programmers: part 5
#20Return value optimization is absolutely allowed in C, and ~all compilers do it. It's not commonly talked about because in C, there can be no side-effects when constructing or copying a struct, so there's nothing to discuss. It just happens automatically and there's no observable change in program behavior.
No, C has much less RVO allowed than C++. I provided an example of this here the last time : https://news.ycombinator.com/item?id=17216250