Error no matching function for call to pow double

No matching function for call to c++ error comes when argument of function is not matching as per expected in function.

When we are calling some function but there is not matching function definition argument, then we get compilation error as No matching function for call to c++. To resolve this error, We need to pass appropriate matching argument during function call. Or need to create different overloaded function with different arguments.

error: no matching function for call to
error: no matching function for call to

Check function calling and function definition argument data types. It must be same.

#include <iostream>
using namespace std;

class A
{
    public:
        void setValue(int value);
        int value;
};

void A::setValue(int value)
{
    value++;
}

int main(int argc, char** argv) 
{
    A obj; 
    obj.setValue(obj);  // ERROR: No matching function for call to
    return 0;
}

Output | error: no matching function for call to

no matching function for call to
no matching function for call to

Here if you see we are passing Class object inside setValue() function calling argument. But if we check in setValue() function definition that we expect passing argument value as integer. So here function calling argument and expected arguments are not matching so we are getting error of no matching function for call to c++.

no matching function for call
no matching function for call

[SOLUTION] How to resolve “No matching function for call to” c++ error ?

int main(int argc, char** argv) 
{
    A obj; 
    int value=0;
    obj.setValue(value); 
    return 0;
}

Here we just modified setValue() function argument as integer. So it will be match with function definition arguments. So no matching function for call to c++ error will be resolve.

Frequently asked queries for No Matching function for call:

1. no matching function for call to / no matching function for call

If function call and function definition arguments are not matching then you might get this error. Depend on compiler to compiler you might get different errors. Sometimes it also give that type mismatch or can not convert from one data type to another.

No matching function for call

2. error: no matching function for call to

You will get error for no matching function call when generally you are passing object / pointer / reference in function call and function definition is not able to match and accept that argument.

Conclusion:

Whenever you are getting no matching function for call to c++ error then check function arguments and their data types. You must be making mistake during function calling and passing mismatch argument or you might be require to add new function with similar matching data type. After checking and adding suitable function argument change your error will be resolve. I hope this article will solve your problem, in case of any further issue or doubt you can write us in comment. Keep coding and check Mr.CodeHunter website for more c++ and programming related articles.

Reader Interactions

Не пойму почему .Я уже менял // for(float a = 0; a < 8; a + 0.5) float на int и всё равно ничего не работает.
///////////////////////////////////////////////////////////////// ! — снизу меняется флоат
main.cpp:23:42: error: no matching function for call to ‘cos(float, double)’
x=(1 — 2 * pow(cos(2 * a, 2.0))) / (2 * (tg((2 * a) — (PI / 4)))) * (pow(sin((PI / 4) + (2 * b)),2.0));

#include <iostream>
#include <math.h>


using namespace std;

int main()
{
    double y; //First
    const double PI = 3.14;
    double x;
    for(float a = 0; a < 8; a + 0.5)
        for(int b = -3; b < 11; b + 0.2){
    {
        if (b!=-3){
            if(a!=4){
        
            x=(pow(sqrt((a-b)/(b+3)),4))+(pow(sqrt((b+a)/(a-4)),4));
        }
            }
        else if(b >= -10){
            if(b < 0){

            x=(1 - 2 * pow(cos(2 * a, 2.0))) / (2 * (tg((2 * a) - (PI / 4)))) * (pow(sin((PI / 4) + (2 * b)),2.0));
       ////////////////////////////////// ^ - ошибка здесь  ////////// ^ - и здесь
 }
        }
        else if (b != a)
        {
            if(b != -a){
            x=(1/(a+b))+(((2*a)-b)/(a-b))-((a+b)/1);
        }
        }
        else
        {
            x=(sqrt(2-a))+((4*b)-3);
        }
    if(x > 12){
    y = ((sqrt(abs(12 + x) - pow(x,2.0)))/(x - 11))-((sqrt(abs(12 + x) - pow(x,2.0)))/(2*x - 9));
        cout << y;
    }
    else(x <= 12);{
       y = (1 + cos(2*x - 2*PI)+cos(4*x + 2*PI) - cos(6*x - PI))/(cos(2*PI - 2*x) + (2*x + PI) - 1)- (2*cos(2*x));
    }
        cout << y ;
    return 0;
}
}
}
main.cpp: In function ‘int main()’:
main.cpp:23:42: error: no matching function for call to ‘cos(float, double)’
             x=(1 - 2 * pow(cos(2 * a, 2.0))) / (2 * (tg((2 * a) - (PI / 4)))) * (pow(sin((PI / 4) + (2 * b)),2.0));
                                          ^
In file included from /usr/include/features.h:374:0,
                 from /usr/include/x86_64-linux-gnu/c++/6/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/6/bits/c++config.h:507,
                 from /usr/include/c++/6/iostream:38,
                 from main.cpp:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:63:1: note: candidate: double cos(double)
 __MATHCALL (cos,, (_Mdouble_ __x));
 ^
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:63:1: note:   candidate expects 1 argument, 2 provided
In file included from /usr/include/c++/6/math.h:36:0,
                 from main.cpp:2:
/usr/include/c++/6/cmath:219:5: note: candidate: template constexpr typename __gnu_cxx::__enable_if::__value, double>::__type std::cos(_Tp)
     cos(_Tp __x)
     ^~~
/usr/include/c++/6/cmath:219:5: note:   template argument deduction/substitution failed:
main.cpp:23:42: note:   candidate expects 1 argument, 2 provided
             x=(1 - 2 * pow(cos(2 * a, 2.0))) / (2 * (tg((2 * a) - (PI / 4)))) * (pow(sin((PI / 4) + (2 * b)),2.0));
                                          ^
In file included from /usr/include/c++/6/math.h:36:0,
                 from main.cpp:2:
/usr/include/c++/6/cmath:211:3: note: candidate: constexpr long double std::cos(long double)
   cos(long double __x)
   ^~~
/usr/include/c++/6/cmath:211:3: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/6/cmath:207:3: note: candidate: constexpr float std::cos(float)
   cos(float __x)
   ^~~
/usr/include/c++/6/cmath:207:3: note:   candidate expects 1 argument, 2 provided
main.cpp:23:75: error: ‘tg’ was not declared in this scope
             x=(1 - 2 * pow(cos(2 * a, 2.0))) / (2 * (tg((2 * a) - (PI / 4)))) * (pow(sin((PI / 4) + (2 * b)),2.0));
                                                                           ^

У меня есть функция шаблона в стиле:

template <int Exponent> DERIVED_TYPE pow(TYPE const x);

Эта функция определена в строковой структуре шаблона как функция друга:

template <ARGUMENTS>
struct unit {
    typedef unit<ARGUMENTS> type;

    ....
    template <int Exponent>
    friend constexpr unit_pow_t<type, Exponent> pow(type const x) { ... }
};

Это связано с тем, что при использовании значения единицы с мощностью необходимо изменить устройство вместе со значением.

Когда я пытаюсь использовать его без экспоненты, я вижу кандидатов, которые компилятор считает для соответствия:

src/model/Tool.cpp:113:3: error: no matching function for call to 'pow'
                pow(1._m);
                ^~~
src/model/../units/Units.hpp:2266:46: note: candidate template ignored: couldn't infer template argument 'Exponent'
        friend constexpr unit_pow_t<type, Exponent> pow(type const x) {
                                                    ^
/usr/include/math.h:255:8: note: candidate function not viable: requires 2 arguments, but 1 was provided
double  pow(double, double);
        ^

До сих пор все было так, как ожидалось, шаблон просматривается, но, конечно же, необходимо указать экспонента. Когда я делаю, что-то неожиданное случается:

src/model/Tool.cpp:113:6: error: comparison between pointer and integer ('double (*)(double, double)' and 'int')
                pow<3>(1._m);
                ~~~^~

Компилятор видит pow как адрес «double pow (double, double)» и интерпретирует < 3 как цель сравнения указателя функции с целым числом. Проблема возникает с clang 3.4, 3.6 и GCC 5.2.

Мой вопрос: как мне убедить компилятор, что < 3 > является списком аргументов шаблона?

UPDATE

Наконец-то мне удалось создать минимальный пример, извините за неполный вопрос:

template <int Exp>
struct metre {
    double value;
    template <int Exponent>
    friend constexpr metre<Exp * Exponent> pow(metre<Exp> const x) {
        return {0};
    }
};

int main() {
    pow<2>(metre<1>{1});
    return 0;
};

Кажется, он не видит pow:

targs.cpp:11:2: error: use of undeclared identifier 'pow'
        pow<2>(metre<1>{1});
        ^

Если я включаю cmath, у меня такая же диагностика, как и раньше:

targs.cpp:13:5: error: comparison between pointer and integer ('double (*)(double, double)' and 'int')
        pow<2>(metre<1>{1});
        ~~~^~
1 error generated.

Таким образом, наличие «double pow (double, double)» просто маскирует проблему, что шаблон не отображается. Тогда возникает вопрос: почему pow < > () не рассматривается компилятором?

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Error no matching distribution found for tkinter
  • Error no matching distribution found for cv2
  • Error no document variable supplied
  • Error no display environment variable specified firefox
  • Error no devices emulators found перевод

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии