获取错误 C++ 即使拥有所有构造函数也没有匹配的调用函数

Getting error C++ no matching function for call even having all constructors

我试图制作一个支持单位数字初始化和重载 * 运算符的 BigInt 库

我有构造函数 "BigInt(int r[])" 仍然 "return BigInt(res)" 不工作,其中 res in int array

感谢您的宝贵时间。

编译器错误“错误:没有匹配函数来调用'BigInt::BigInt(BigInt)' return BigInt(res);

这是我在Qt Creator中编译的代码

#include <iostream>

using namespace std;

class BigInt{
public:
    int h[1000];

    BigInt(){
        for(int i=0; i<1000; i++) h[i] = -1;
    }
    BigInt(int n){
        for(int i=0; i<1000; i++) h[i] = -1;
        h[0] = n;

        //Assuming single digit
    }
    BigInt(int r[]){
        for(int i=0; i<1000; i++) h[i] = r[i];
    }
    BigInt(BigInt &b){
        for(int i=0; i<1000; i++) h[i] = b.h[i];
    }

    BigInt operator*(int n){
        int carry = 0;
        int res[1000] = {-1};

        int *a = &h[0];
        int *b = &res[0];

        while(1){

            int unitDigit = n*(*a) + carry;
            carry = unitDigit/10;
            unitDigit %= 10;

            *b = unitDigit;
            b++;
            a++;

            if(*a == -1){
                break;
            }

        }

        while(carry){
            int unitDigit = carry % 10;
            *b = unitDigit;
            carry /= 10;
            b++;
        }

        return BigInt(res);
    }

    friend ostream& operator<<(ostream &out, BigInt &b){
        int i;
        for(i = 999; b.h[i] == -1; i--)
            ;

        for(; i>=0; i--){
            out<<b.h[i];
        }

        return out;
    }
};

int main(){

    int input;
    cin>>input;

    BigInt result(1);

    for(int i=2; i<input; i++){
        result = result*i;
    }

    cout<<result<<endl;
    return 0;
}

BigInt(int r[]) 构造函数更改为 BigInt(const int *r)

不要尝试复制数组;改为指向它们。

你有一个构造函数

  BigInt(BigInt &b){
     for(int i=0; i<1000; i++) h[i] = b.h[i];
  }

这似乎不对。如果你想提供一个复制构造函数,参数需要是 const&.

  BigInt(BigInt const&b){
     for(int i=0; i<1000; i++) h[i] = b.h[i];
  }

更改后,我能够使用您发布的代码构建程序。