元组作为函数参数中的默认值
Tuple as default value in function parameter
如何将元组作为函数的默认值?
这些原型引发编译错误:
void f(std::tuple<int, int>=std::tuple<int, int>(1, 1));
void f(std::tuple<int, int>=std::make_tuple(1, 1));
void f(std::tuple<int, int>=(1, 1));
void f(std::tuple<int, int> t = std::make_tuple(1, 1));
或
void f(std::tuple<int, int> = std::make_tuple(1, 1));
或
void f(std::tuple<int, int> = std::tuple<int, int>(1, 1));
或
void f(std::tuple<int, int> = std::tuple<int, int>{1, 1});
整个事情是你错过了名字 :) 你忘了给你的变量命名。
void f(std::tuple<int, int>x=std::make_tuple(1., 1.))
应该可以
查看此 docs 了解更多信息。
attr(optional) decl-specifier-seq declarator = initializer
您的定义中缺少 "declarator" 部分。
Each declarator introduces a single variable or function into the
program. The most simple form of declarator is just the name you're
introducing - the declarator-id.
你只缺一个 space:
void f(std::tuple<int, int> =std::make_tuple(1, 1));
照原样,>=
被解析为单个标记。
添加一个变量名也可以方便地回避这个问题。
如何将元组作为函数的默认值?
这些原型引发编译错误:
void f(std::tuple<int, int>=std::tuple<int, int>(1, 1));
void f(std::tuple<int, int>=std::make_tuple(1, 1));
void f(std::tuple<int, int>=(1, 1));
void f(std::tuple<int, int> t = std::make_tuple(1, 1));
或
void f(std::tuple<int, int> = std::make_tuple(1, 1));
或
void f(std::tuple<int, int> = std::tuple<int, int>(1, 1));
或
void f(std::tuple<int, int> = std::tuple<int, int>{1, 1});
整个事情是你错过了名字 :) 你忘了给你的变量命名。
void f(std::tuple<int, int>x=std::make_tuple(1., 1.))
应该可以
查看此 docs 了解更多信息。
attr(optional) decl-specifier-seq declarator = initializer
您的定义中缺少 "declarator" 部分。
Each declarator introduces a single variable or function into the program. The most simple form of declarator is just the name you're introducing - the declarator-id.
你只缺一个 space:
void f(std::tuple<int, int> =std::make_tuple(1, 1));
照原样,>=
被解析为单个标记。
添加一个变量名也可以方便地回避这个问题。