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*

9
  • 4
    The correct implementation is just let the compiler generate it. class C { std::string string; }; Commented May 1, 2012 at 18:24
  • 2
    This is of course a simple example. I do need a move constructor. What do I do with the string in this case? Ignore it? Commented May 1, 2012 at 18:26
  • 2
    The first one constructs string, then moves. The second one is better. Also: don't name variables the same as a type. Option B should be moving the string. Commented May 1, 2012 at 18:30
  • 3
    @Fraser: (1) OP mentioned gcc 4.8, which does automatically generate move c'tors (even 4.7 does), and (2) that's VC11's bug. Commented May 1, 2012 at 18:34
  • 1
    @KennyTM I know gcc was mentioned, but it's probably not good advice at the moment to rely on compiler generated move constructors unless it's clear that only compliant compilers will be used. (Also, I wouldn't call this a bug so much as missing functionality) Commented May 1, 2012 at 18:39