initializing a non-copyable member (or other object) in-place from a factory function

前端 未结 2 529
醉酒成梦
醉酒成梦 2021-02-04 01:43

A class must have a valid copy or move constructor for any of this syntax to be legal:

C x = factory();
C y( factory() );
C z{ factory() };

In

2条回答
  •  粉色の甜心
    2021-02-04 02:38

    Issues like this were among the prime motivations for the change in C++17 to allow these initializations (and exclude the copies from the language, not merely as an optimization).

提交回复
热议问题