-1

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.

Community
  • 1
  • 1
Phobos D'thorga
  • 439
  • 5
  • 17

2 Answers2

1

You're pasing rescode, which is a long, where the code expects a vector<T>, as the first parameter of anydup().

lorro
  • 10,687
  • 23
  • 36
0

You should specify the type for template function, like this:

info.response_code = gk::anydup<long>(rescode, sizeof(long));

Upd: and anydup returns vector, but you assign it to long.

maxon
  • 1
  • 1
  • Look at my update. You should change return type of anydup to T, or change response_code to vector, dependently of what are you want to achieve – maxon Sep 25 '16 at 21:18
  • And, as lorro marked, you pass long to function expects vector. What is a point of function anydup? – maxon Sep 25 '16 at 21:23