#include "boost/optional.hpp" #include using Optional_t = boost::optional; // Emits warning //using Optional_t = std::experimental::optional; // Works fine struct A { A(const Optional_t& iOptional) :_optional(iOptional) {} Optional_t _optional; }; const Optional_t& getAnOptional(); void useA(A&); void someFunction(const void* iSomeData) { Optional_t aOptional; if (iSomeData) { aOptional = getAnOptional(); } A* aA = new A(aOptional); useA(*aA); }