Скажем, у меня есть следующий класс:
#include
class A {
private:
std::optional i;
// other stuff
}
Как бы мне спроектировать этот конструктор, чтобы он имел идиоматический современный стиль C++?
constexpr A()
: i(std::nullopt)
{ }
constexpr A(int i)
: i(i)
{ }
// or
constexpr A(std::optional opt = std::nullopt)
: i(opt )
{ }
// different suggestions?
Подробнее здесь: https://stackoverflow.com/questions/787 ... onstructor
Мобильная версия