Witam napisałem kod, w którym umieściłem szablon z wieloma parametrami chcąc sprawdzić jak będzie działał. Mam problem, ponieważ i właśnie oto chodzi dlaczego wystąpił problem.
oto kod:
#include <iostream>
#include <string>
template <typename T>
void Fun(T &w, T a, T b, T arr[], T z);
int main()
{
std::string cp = "Slowo";
int k=14, l=25, m=2;
char biblia[m] = {'L', 'k'};
Fun(cp, k, l, biblia, m);
return 0;
}
template <typename T>
void Fun(T &w, T a, T b, T arr[], T z)
{
std::cout << "\"" << w << "\": " << a << "," << b << " " << arr[0] << arr[1] << std::endl;
}
a oto błędy, które występują:
srednie.cpp:12:25: error: no matching function for call to ‘Fun(std::__cxx11::string&, int&, int&, char [m], int&)’
Fun(cp, k, l, biblia, m);
^
srednie.cpp:5:6: note: candidate: template<class T> void Fun(T&, T, T, T*, T)
void Fun(T &w, T a, T b, T arr[], T z);
^~~
srednie.cpp:5:6: note: template argument deduction/substitution failed:
srednie.cpp:12:25: note: deduced conflicting types for parameter ‘T’ (‘std::__cxx11::basic_string<char>’ and ‘int’)
Fun(cp, k, l, biblia, m);