Unresolved overloaded function type when attempting to pass a function as an argument

Ziyad Edher

I receive the following error when attempting to compile a lone C++ testing file under G++ with C++11 in place.

spike/cur_spike.cpp: In function ‘int main()’:
spike/cur_spike.cpp:60:44: error: no matching function for call to ‘callFunctionFromName(<unresolved overloaded function type>, std::__cxx11::string&)’
     callFunctionFromName (outputLine, param);
                                            ^
spike/cur_spike.cpp:49:7: note: candidate: template<class funcT, class ... Args> funcT callFunctionFromName(funcT (*)(Args ...), Args ...)
 funcT callFunctionFromName (funcT func(Args...), Args... args) {
       ^
spike/cur_spike.cpp:49:7: note:   template argument deduction/substitution failed:
spike/cur_spike.cpp:60:44: note:   couldn't deduce template parameter ‘funcT’
     callFunctionFromName (outputLine, param);
                                            ^

Here's the code.

#include <iostream>
#include <string>


template <typename T>
void outputLine (T text) {
    std::cout << text << std::endl;
}

template <typename funcT>
funcT callFunctionFromName (funcT func()) {
    return func ();
}
template <typename funcT, typename... Args>
funcT callFunctionFromName (funcT func(Args...), Args... args) {
    return func (args...);
}

int main () {  
    std::string param = "Testing...";
    callFunctionFromName (outputLine, param);

    return 0;
}

I'm currently building this on a Linux system using G++, this code snippet contains all code related to this issue. I'm particularly intrigued about the fact that the compiler is unable to deduce the template parameter funcT for some reason, even though the outputLine function has a clear return type of void.

Setting a pointer of outputLine using void (*outputLinePtr)(std::string) = outputLine and using the pointer as the argument instead does nothing. Any help would be much appreciated.

ForEveR

You can manually set template argument.

callFunctionFromName (outputLine<std::string>, param);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Unresolved overloaded function type when attempting to pass a function as an argument

From Dev

wrapping template function and <unresolved overloaded function type

From Dev

Unresolved overloaded function type, clone for_each

From Dev

"unresolved overloaded function type" with static function in std::function

From Dev

How to solve the error: "no matching function for call to ‘bind(<unresolved overloaded function type>" when std::bind is used in a class

From Dev

How to solve the error: "no matching function for call to ‘bind(<unresolved overloaded function type>" when std::bind is used in a class

From Dev

<unresolved overloaded function type> with member function pointer and templates

From Dev

error: no matching function for call to 'sort(..., ..., <unresolved overloaded function type>)'

From Dev

No matching function for call to std::transform, unresolved overloaded function type

From Dev

<unresolved overloaded function type> with member function pointer and templates

From Dev

Invalid static_cast from type <unresolved overloaded function type>

From Dev

template function as argument to template function - unresolved function type error

From Dev

mem_fun_ref: unresolved overloaded function type

From Dev

sort on a class member got the error unresolved overloaded function type

From Dev

Invalid operands of types ‘int’ and ‘<unresolved overloaded function type>’ to binary ‘operator<<’

From Dev

unresolved overloaded function error when binding to std::operator==

From Dev

QBasic pass type as function argument

From Dev

when to pass a pointer argument to a function

From Dev

Trying to pass a function as an argument to a timer, unresolved linker error

From Dev

"no matching function for call to ‘async(std::launch, <unresolved overloaded function type>, std::string&)’"

From Dev

error: conversion from ‘<unresolved overloaded function type>’ to non-scalar type

From Dev

error: conversion from ‘<unresolved overloaded function type>’ to non-scalar type

From Dev

Pass function as argument to function

From Dev

Pass function as argument to a function

From Dev

Pass `struct` as type name to function argument

From Dev

Pass lambda by argument (no function type template)

From Dev

error: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<<'

From Dev

C++ error: invalid Operands of types 'double' and <unresolved overloaded function type' to binary 'operator'

From Dev

C++ error: invalid Operands of types 'double' and <unresolved overloaded function type' to binary 'operator'

Related Related

  1. 1

    Unresolved overloaded function type when attempting to pass a function as an argument

  2. 2

    wrapping template function and <unresolved overloaded function type

  3. 3

    Unresolved overloaded function type, clone for_each

  4. 4

    "unresolved overloaded function type" with static function in std::function

  5. 5

    How to solve the error: "no matching function for call to ‘bind(<unresolved overloaded function type>" when std::bind is used in a class

  6. 6

    How to solve the error: "no matching function for call to ‘bind(<unresolved overloaded function type>" when std::bind is used in a class

  7. 7

    <unresolved overloaded function type> with member function pointer and templates

  8. 8

    error: no matching function for call to 'sort(..., ..., <unresolved overloaded function type>)'

  9. 9

    No matching function for call to std::transform, unresolved overloaded function type

  10. 10

    <unresolved overloaded function type> with member function pointer and templates

  11. 11

    Invalid static_cast from type <unresolved overloaded function type>

  12. 12

    template function as argument to template function - unresolved function type error

  13. 13

    mem_fun_ref: unresolved overloaded function type

  14. 14

    sort on a class member got the error unresolved overloaded function type

  15. 15

    Invalid operands of types ‘int’ and ‘<unresolved overloaded function type>’ to binary ‘operator<<’

  16. 16

    unresolved overloaded function error when binding to std::operator==

  17. 17

    QBasic pass type as function argument

  18. 18

    when to pass a pointer argument to a function

  19. 19

    Trying to pass a function as an argument to a timer, unresolved linker error

  20. 20

    "no matching function for call to ‘async(std::launch, <unresolved overloaded function type>, std::string&)’"

  21. 21

    error: conversion from ‘<unresolved overloaded function type>’ to non-scalar type

  22. 22

    error: conversion from ‘<unresolved overloaded function type>’ to non-scalar type

  23. 23

    Pass function as argument to function

  24. 24

    Pass function as argument to a function

  25. 25

    Pass `struct` as type name to function argument

  26. 26

    Pass lambda by argument (no function type template)

  27. 27

    error: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<<'

  28. 28

    C++ error: invalid Operands of types 'double' and <unresolved overloaded function type' to binary 'operator'

  29. 29

    C++ error: invalid Operands of types 'double' and <unresolved overloaded function type' to binary 'operator'

HotTag

Archive