recently i was testing some c++ template codes and i found one mind-boggling error. According to my research on internet in particular stackoverflow, this code is completely valid however, compiler raises compile time error. Error is located below of code.
Code:
template<template<class> class C, typename T> void print(C<T>& c) {
}
int test() {
vector<string> v(5, "Yow!");
print(v);
return 0;
}
Compiler Output:
In function ‘int test()’:
error: no matching function for call to ‘print2(std::vector<std::basic_string<char> >&)’
note: candidate is:
note: template<template<class> class C, class T> void print2(C<T>&)
It seems something is wrong about definition or my compiler but i tested this code with both g++ and clang++ in order to be sure about there is not any compiler dependent problem. Both of them raises same error.
I really appreciate any meaningful comments which aim to make clarification for this problem.
Thank you