具有std :: array的C ++模板函数 [英] C++ template function with std::array
问题描述
我具有以下功能:
template <typename T, size_t SIZE>
void minSortLoop(array<T, SIZE>& a){
for(size_t o = 0; o < SIZE; o++) {
size_t minIx = 0;
for(size_t i = o + 1; i < SIZE; i++) {
if(a[i] < a[minIx]) {
minIx = i;
}
}
swap(a[o], a[minIx]);
}
}
我喜欢从其他位置调用它,
I like to call it from the other location like:
std::array<int, 3> arr = {3,1,-9};
minSortLoop(arr);
但是我得到了错误:
描述资源路径位置类型无效的参数'候选是:void minSortLoop(?&)'Test.cpp/g测试第23行语义错误
Description Resource Path Location Type Invalid arguments ' Candidates are: void minSortLoop(? &) ' Test.cpp /gTest line 23 Semantic Error
描述资源路径位置类型没有匹配的呼叫功能到'minSortLoop(std :: array *)'Test.cpp/g测试第23行C/C ++问题
Description Resource Path Location Type no matching function for call to 'minSortLoop(std::array*)' Test.cpp /gTest line 23 C/C++ Problem
如何正确调用排序函数?
How do I call my sort function correctly ?
最诚挚的问候:-)
PS:不允许使用std :: sort.
PS: I'm not allowed to use std::sort.
@FrançoisMoisan:
@François Moisan:
我试图通过其他方式通过:
I've tried to pass in other ways like:
std::array<int, 3> arr = {3,1,-9};
minSortLoop(&arr);
有错误:
描述资源路径位置类型无效的参数'候选是:void minSortLoop(?&)'Test.cpp/g测试第23行语义错误
Description Resource Path Location Type Invalid arguments ' Candidates are: void minSortLoop(? &) ' Test.cpp /gTest line 23 Semantic Error
描述资源路径位置类型没有匹配的呼叫功能到'minSortLoop(std :: array *)'Test.cpp/g测试第23行C/C ++问题
Description Resource Path Location Type no matching function for call to 'minSortLoop(std::array*)' Test.cpp /gTest line 23 C/C++ Problem
和:
std::array<int, 3> arr = {3,1,-9};
minSortLoop(*arr);
有错误:
描述资源路径位置类型无效的参数'候选是:void minSortLoop(?&)'Test.cpp/g测试第23行语义错误
Description Resource Path Location Type Invalid arguments ' Candidates are: void minSortLoop(? &) ' Test.cpp /gTest line 23 Semantic Error
描述资源路径位置类型与操作符*"不匹配(操作数类型为'std :: array')Test.cpp/g测试第23行C/C ++问题
Description Resource Path Location Type no match for 'operator*' (operand type is 'std::array') Test.cpp /gTest line 23 C/C++ Problem
不确定如何称呼它.该参考建议类似于我的第一个示例此处.
Not sure how to call this. The reference suggests something like my first example here.
@tadman:
我需要传递尺寸.这是从任务描述中给出的:-(
I need to pass the size. That's given from the task description :-(
@ Jarod42:这是哪个编译器?我在Windows 7下的Eclipse中使用Cygwin.
@Jarod42: Which compiler is this ? I'm using Cygwin in eclipse under windows 7.
@pasasap:是的,我编译了它,或者至少尝试了.导致描述的错误.
@pasasap: Yes, I compiled it or at least I try. It results in the described errors.
正如@pasasap在评论之一中提到的那样,问题似乎是由于日食引起的.没有人知道解决方案而不关闭cody-analysis吗?
As @pasasap mentioned in one of the comments, it seems like the problem is because of eclipse. Does anyone know a solution without turning off cody-analysis ?
推荐答案
问题是我的IDE Eclipse.一旦我关闭了代码分析功能,它就会按预期进行编译.
The problem is my IDE Eclipse. Once I turned off the code analysis feature it compiled as expected.
这篇关于具有std :: array的C ++模板函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!