c++ - comma in function arguments causes strange argument split in codeblocks
问题描述
I'm trying to write a function that can take vectors containing int arrays with a length of 3 as an argument. After a bit of reading I was instructed to do this by putting a std::array into a std::vector. However I cannot seem to figure out how to do this.
Here's my code:
#include <vector>
#include <array>
void example(int unrelated_argument1, std::vector<std::array<int, 3> > argument, int unrelated_argument);
void example(int unrelated_argument1, std::vector<std::array<int, 3> > argument, int unrelated_argument)
{
for(unsigned int i = 0; i < argument.size(); i++)
{
printf("Contents of array number %i are %i %i %i\n", i, argument[i][0],argument[i][1], argument[i][2]);
}
}
int main()
{
std::vector<std::array <int, 3> >test_vector;
std::array<int, 3> test_array1 = {1, 2, 3};
std::array<int, 3> test_array2 = {10, 20, 30};
std::array<int, 3> test_array3 = {1000, 2000, 3000};
test_vector.push_back(test_array1);
test_vector.push_back(test_array2);
test_vector.push_back(test_array3);
example(0, test_vector, 0);
}
I expected the function called example
to take 3 arguments here, however my IDE(codeblocks) claims that this results in 4 arguments:
Those being int unrelated_argument1
, std::vector<std::array<int
, 3> > argument
and int unrelated_argument2
.
The second and third arguments here are incorrect: I expected the argument to be std::vector<std::array<int, 3> > argument
instead.
What am I doing incorrectly here?
Edit: After a whole bit more reading and research, it seems that this is a known bug in codeblocks. https://sourceforge.net/p/codeblocks/tickets/491/ The code here appears to be correct.
解决方案
经过更多研究,这似乎确实是代码块中的一个错误,而不是上面的代码。https://sourceforge.net/p/codeblocks/tickets/491/截止到这篇文章,最新的稳定版(17.12)仍然有这个bug。如果您也遇到此错误,您可能想尝试其中一个夜间构建。
推荐阅读
- amazon-web-services - 在不停机的情况下替换 CloudFront 分配上的 SSL 证书
- flutter - 页面加载后如何启动 AnimatedContainer 动画?
- java - 将文件中的键值对添加到 Hashmap
- python-3.x - 使用 Nginx + Gunicorn + Flask 时 Websocket 连接失败
- php - axios 和 vuex 正在删除数组中的错误索引
- prolog - 来自不同城市的候选人名单
- php - 使用正则表达式从 PHP 中的 JS 对象文字字符串中提取一些数据
- laravel - 如何调用 .env {{ env('APP_NAME} }} 到 laravel 刀片模板?
- c# - uwp beforetextchanged 光标在文本前面移动
- ibm-cloud - 如何仅从变量中提取数字