i have a template class and inside i have function operator>
which should call a template function from another file. How do i set the function parameters or how do i have to pass the arguments to this function.
I have removed the code from the lambda function and the cmpFn, because this should be irrelevant for this example.
This is my template class, in which the operator<
calls the function cmpFn
.
NOTE: In a previous version of this question, i have falsely declared the function header of the cmpFn
.
#include "assert.h"
template <typename T>
class myvectest
{
public:
T *arr;
unsigned capacity;
unsigned current;
myvectest()
{
capacity = 1;
arr = new T[capacity];
current = 0;
}
unsigned size() const
{
return current;
}
bool operator<(const myvectest &toCompare) const
{
auto mfn = [ ](auto left, auto right) -> int { return 0 };
return cmpFn(this->arr, toCompare.arr, this->size(), toCompare.size(), mfn);
}
}
This is the cmpFn
, in which i updated the paramter *a and *b
template <typename T>
bool cmpFn(T *a, T *b, unsigned size1, unsigned size2, int (*fnEq)(T, T))
{
return false;
}
The error message tells me, that there is no matching function call, even if there is a candidate.
.../myvectest.h:83:21: error: no matching function for call to ‘cmpFn(unsigned int* const&, unsigned int* const&, myvectest <T>::operator<(const myvectest<T>&) const [with T = unsigned int]::<lambda(auto:1, auto:2)>)’
83 | return cmpFn(
| ~~~~~^
84 | this->arr,
| ~~~~~~~~~~
85 | toCompare.arr,
| ~~~~~~~~~~~~~~
86 | [ ](auto left, auto right) -> int { return 0; }
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87 | );
| ~
I know, that there could be other solutions, but i want to learn, how this kind of passing an array should work.
Thanks in advance, Ulf
EDIT: Note, that the myvectest->arr
is from dynamic size. Since this is some kind of rebuilding the std::vector
class, there is also a push_back method, which can change the size and capacity of *arr