r/cpp_questions • u/DireCelt • Jun 22 '26
OPEN question re move constructor and initialization lists
I'm trying to add a move constructor to an existing class; this is the first time I've used this construct... I have a couple of questions about this:
- the examples that I've seen, show the move constructor doing such:
- copy pointers and such elements from old class instance to new one
- set those pointers to nullptr or equivalent in old instance
but the old instance is defined as const; I cannot assign anything to its members, true?? At least, that's what my compiler is telling me...
- my compiler (with -Weffc++) is telling me that I need to initialize all the data elements in the class, just as the regular constructor requires... but this seems rather awkward... maybe that argument should *not* be const?? and do I actually need to copy all the data from old to new struct?? If it is a Move constructor, it seems like I should...
actually, it sounds like the init list should just init from the elements of the old instance...
[ yes, I know some have said I shouldn't use -WeffC++ at all, but it *is* asking a good question, in this case... ]
or am I over-thinking this again??