I asked a question here and got an excellent response from the community: A templated 'strdup()'?
But now, when I do the following:
struct CurlInfo {
long response_code;
std::string effective_url;
};
CurlInfo info;
CURL *curl = curlInit(url, "", "");
if (curl != nullptr) {
long rescode;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &rescode);
}
info.response_code = gk::anydup(rescode, sizeof(long));
With the following template:
template<typename T>
std::vector<T> anydup(std::vector<T> &src, size_t len) {
std::vector<T> v(len);
std::copy(src.cbegin(), src.cend(), v);
return v;
}
I get the following:
/home/phobos/Programming/FyreDL/src/cmnroutines.cpp:89:66: error: no matching function for call to 'anydup(long int&, long unsigned int)'
info.response_code = gk::anydup(rescode, sizeof(long));
^
In file included from /home/phobos/Programming/FyreDL/src/cmnroutines.cpp:43:0:
/home/phobos/Programming/FyreDL/src/cmnroutines.hpp:89:16: note: candidate: template<class T> std::vector<T> gk::anydup(std::vector<T>&, size_t)
std::vector<T> anydup(std::vector<T> &src, size_t len) {
^~~~~~
/home/phobos/Programming/FyreDL/src/cmnroutines.hpp:89:16: note: template argument deduction/substitution failed:
/home/phobos/Programming/FyreDL/src/cmnroutines.cpp:89:66: note: mismatched types 'std::vector<T>' and 'long int'
info.response_code = gk::anydup(rescode, sizeof(long));
^
Why am I getting this and what is the solution to my problem? Any help will be greatly appreciate and thank you in advance.