• C++异常:no matching function for call to "Matrix(Matrix&)"


    C++异常:no matching function for call to "Matrix(Matrix&)"

    我定义了一个类叫Matrix,其中构造函数explicit Matrix(const Matrix& source);

    也写了一个方法:

    Matrix Matrix::myFun(const Matrix &source)
    {
      ...

        return *this;
    }

    编译报出上面的异常来,原因是explicit关键字抑制隐式转换,当我返回*this的时候相当于:Matrix myMatrix = *this,由于禁止隐式转换,所以这个是报错的。

    当我删掉explicit关键字后,发生了隐式转换:Matrix tmp(*this),然后调用编译器提供的默认复制构造函数Matrix myMatrix(tmp)。则顺利通过编译。

  • 相关阅读:
    samba
    sed用法
    Jenkins流水线项目发布流程
    Jenkins
    CI/CD
    tomcat
    gitlab
    rsync
    HAPROXY
    基于LVS的web集群部署(http)
  • 原文地址:https://www.cnblogs.com/Shirlies/p/3719892.html
Copyright © 2020-2023  润新知