C++异常:no matching function for call to "Matrix(Matrix&)"
2014-05-10 00:24
696 查看
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)。则顺利通过编译。
我定义了一个类叫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)。则顺利通过编译。
相关文章推荐
- cocos2d-2.1beta3-x-2.1.1 "no matching function for call to..."
- 【求助】 no matching function for call to `strcpy(std::string&, char*&)'
- Qt error ------ no matching function for call to QObject::connect(QSpinBox*&, <unresolved overloaded function type>, QSlider*&, void (QAbstractSlider::*)(int))
- no matching function for call to ‘std::basic_string<char>::assign(std::string&, int)
- error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
- no matching function for call to "namespace::class1::foo(class2&)"
- error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
- error: no matching function for call to 'MainWindow::connect(*&, ...)
- no matching function for call to 'strstr(stdstring&, const char [4])'
- error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
- error: no matching function for call to 'std::exception:exception(const char[16])'
- NDK编译出现找不到函数定义 no matching function for call to
- error: no matching function for call to ‘ptr_fun(<unresolved overloaded function type>)’
- error: no matching function for call to
- C++中错误no matching function for call to transform
- error: extra qualification 以及 error: no matching function for call to
- G++编译错误 no matching function for call to '_tag_data_value::StringAddLen(std::string, int, int)
- iOS linker错误之no matching function for call to ’recvfrom’
- no matching function for call to ‘transform
- [c++]no matching function for call to ‘sort(…)......