#include class My_Container { public: My_Container() = default; My_Container(int x) : x {new int{x}} { } int get_value() { return *x; } bool has_value() { return x != nullptr; } private: int* x {}; }; int test1(My_Container container) { if (container.has_value()) { return container.get_value(); } return -1; } int test2(My_Container const& container) { if (container.has_value()) { return container.get_value(); } return -1; } int main() { My_Container c1 {5}; My_Container const c2 {3}; std::cout << test1(c1) << std::endl; std::cout << test1(c2) << std::endl; std::cout << test2(c1) << std::endl; std::cout << test2(c2) << std::endl; }