c++ - 使用 std::optional 通过引用将 std::vector<int> 传递给函数

标签 c++ std c++17 stdoptional

我不清楚通过引用将可选的整数 vector 传递给函数的正确代码是否是:

void test_func(std::optional<std::vector<int>&> vec)

void test_func(std::optional<std::vector<int>>& vec)

非常感谢任何帮助。

最佳答案

非拥有指针是可为空的引用类型。

void test_func(std::vector<int>* vec)

关于c++ - 使用 std::optional 通过引用将 std::vector<int> 传递给函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53688933/

相关文章:

c++ - 在 std::bind 上使用 std::apply

c++ - 花括号和圆括号之间的参数评估顺序

c++ - 为什么我不能推断静态成员函数是否存在

c++ - 为什么 vector::erase 似乎会导致崩溃?

c++ - 编译时对 boost::system::system_category() 的 undefined reference

c++ - Qt 和 C++ : app crashes only in debug mode

c++ - 当目标指针不是基类的类型时,为什么允许dynamic_cast为多态类生成空指针?

c++ - 我是否必须释放 New 在 C++ 接口(interface)的 Opencv C 包装器中分配的内存

c++ - 无法使用 C++ stdlib 系统调用运行 make

c++ - 运算符 << 重载