所以我想将一个std :: strings数组传递给一个函数。数组中std :: strings的数量是通过preproc预先定义的。指令。整个过程应如下所示:
#define ARRAYSIZE 3
void foo(std::string[ARRAYSIZE]);
void foo(std::string instrings[ARRAYSIZE])
{
...
}
问:我可以先调用该函数而不必先将std :: string数组保存到变量,然后再调用该函数吗?所以基本上我想用一行来调用它,例如:
void main()
{
...
foo( std::string x[ARRAYSIZE] = {"abc","def","ghi"} );
...
}
问题是我无法弄清楚函数调用的正确语法(我什至不确定是否有一种函数调用),Visual Studio的智能感知使我的想法不断下降。
如果您要切换到std::vector
可以即时构建的结构(如您在问题注释中所提到的那样),则该方法应该可以工作(适用于gcc):
void foo(const std::vector<std::string> &stringVec)
{
}
int main()
{
foo( std::vector<std::string>({"abc","def","ghi"}));
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句