我正在用 C++ 编写一个用于矩阵运算的小型矩阵库。然而,我的编译器抱怨了,而以前却没有。这段代码被搁置了六个月,在这期间我将我的计算机从Debian 4.0(蚀刻)至Debian 5.0(莱尼)(g++(Debian 4.3.2-1.1)4.3.2)。但是,我有同样的问题Ubuntu具有相同 g++ 的系统。
这是我的矩阵类的相关部分:
namespace Math
{
class Matrix
{
public:
[...]
friend std::ostream& operator<< (std::ostream& stream, const Matrix& matrix);
}
}
和“实施”:
using namespace Math;
std::ostream& Matrix::operator <<(std::ostream& stream, const Matrix& matrix) {
[...]
}
这是编译器给出的错误:
Matrix.cpp:459: 错误: 'std::ostream&
数学::矩阵::运算符
我对这个错误有点困惑,但在这六个月里做了很多 Java 工作之后,我的 C++ 又变得有点生疏了。 :-)
我只是告诉你另一种可能性:我喜欢使用朋友定义:
namespace Math
{
class Matrix
{
public:
[...]
friend std::ostream& operator<< (std::ostream& stream, const Matrix& matrix) {
[...]
}
};
}
该函数将自动定位到周围的命名空间Math
(即使它的定义出现在该类的范围内),但除非您使用 Matrix 对象调用operatorMath::Matrix<TypeA, N>.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)