I created a function template. It works fine if I use it in functions. Now, I'd like to use it inside a class but can't make the code compile:
#include <QList>
// Function template
template <typename T>
void Array2QList(QList<T> &outList, const T in[], int &insize)
{
for (int i = 0; i < insize; ++i)
outList.append(in[i]);
}
// Class using the template
class Parser
{
public:
Parser(const unsigned char buffer[], const int numBytes){
Array2QList<>(frame, buffer, numBytes); // This one fails
}
~Parser(){}
QList<unsigned char> frame;
};
// Main
int main(int argc, char *argv[])
{
int size = 50;
unsigned char buffer[size];
QList<unsigned char> frame;
Array2QList<unsigned char>(frame, buffer, size); // This one works
Parser parser = Parser(buffer, size);
return 0;
}
The error I get is:
..\SandBox\main.cpp: In constructor 'Parser::Parser(const unsigned char*, int)':
..\SandBox\main.cpp:20: error: no matching function for call to 'Array2QList(QList&, const unsigned char*&, const int&)'
Note: I must arrays since it is an interface for a USB driver.