There is no function template that matches the parameter list

光辉 韦 41 Reputation points
2021-02-05T07:08:24.117+00:00

include <iostream>

using namespace std;
template <class T>
class A
{
private:
T abc;
public:
void(A<T>::*oP)(T k);
typedef void (A<T>::P)(T k);
A(T g) {
this->abc = g;
}
template<class To>
To show(To o) {
std::cout << "hi";
};
template<class L>
A
fun(P o) {
o =&show;
return nullptr;
};
void func(int p) {};
};
namespace ko {
int s = 90;
}
typedef void (A<int>::*oP)(int);
int main() {
oP cd;
cd= &A<int>::func;
A<int> p(90);
A<int> o(0);

auto l=p.fun(cd);

}

Developer technologies | C++
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Igor Tandetnik 1,116 Reputation points
    2021-02-06T04:40:24.487+00:00

    fun is a function template. Its template parameter L doesn't appear anywhere in the function signature, and so cannot be deduced from the arguments. The only way to call fun is to provide the template argument explicitly, as in p.fun<SomeType>(cd)

    Now, it's unclear why fun is made template, seeing as it doesn't use L at all.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.