У меня есть следующий шаблон класса в "concurrent_sorted_list.h":
template <typename T, int (* Compare)(T,T)>
class ConcurrentSortedList{
....
}
в моем main.cpp:
int (*intCompare)(int, int) = [](int a, int b) -> int {
if (a < b)
return -1;
else if (a == b)
return 0;
return 1;
};
ConcurrentSortedList<int, decltype(intCompare)> c;
c.Add(5);
c.Add(6);
assert(c.Size() == 2);
Но я получаю следующую ошибку компилятора: expected a constant of type ‘int (*)(T, T)’, got ‘int (*)(int, int)’
, если я изменю decltype(intCompare)
на intCompare
, тогда я получаю следующую ошибку компилятора: the value of ‘intCompare’ is not usable in a constant expression, ‘intCompare’ was not declared ‘constexpr’, ‘intCompare’ is not a valid template argument for type ‘int (*)(int, int)’, it must be the address of a function with external linkage