[Error] no match for 'operator=' (operand types are 'HCNode' and 'char**')是什么错误?怎么改正?
时间: 2023-05-30 10:04:18 浏览: 1371
这个错误提示是因为在程序中试图将一个char**类型的值赋值给了一个HCNode类型的变量,而这两种类型之间并没有定义赋值运算符(operator=)。
要改正这个错误,需要确定应该将哪些值赋给HCNode类型的变量。如果这个变量需要一个char**类型的值,可以使用一个适当的构造函数或者转换函数来完成类型转换。具体实现方法需要根据代码逻辑和语义来决定。
相关问题
[Error] no match for 'operator=' (operand types are 'HCNode' and 'char**')是什么错误?
这是因为在程序中有一个将字符数组赋值给 HCNode 类型的变量的操作,但是 HCNode 类型没有定义接受字符数组类型的赋值操作符(operator=),因此编译器报错。您需要检查程序中的 HCNode 类型变量赋值操作是否正确,并确保 HCNode 类型定义了正确的赋值操作符。
289 6 D:[Error] no match for operator<< (operand types are std::ostream {aka std::basic_ostream<char> } and Matrix<double> )
这个错误提示是因为你想要使用 `operator<<` 将 `Matrix<double>` 类型的对象输出到标准输出流,但是该类型并没有重载该运算符。
你可以自己实现该运算符的重载。以下是一个示例:
```c++
#include <iostream>
#include <vector>
class Matrix {
public:
Matrix(int rows, int cols) : rows_(rows), cols_(cols), data_(rows * cols) {}
double& operator()(int row, int col) {
return data_[row * cols_ + col];
}
double operator()(int row, int col) const {
return data_[row * cols_ + col];
}
int rows() const {
return rows_;
}
int cols() const {
return cols_;
}
private:
int rows_;
int cols_;
std::vector<double> data_;
};
std::ostream& operator<<(std::ostream& os, const Matrix& matrix) {
for (int i = 0; i < matrix.rows(); ++i) {
for (int j = 0; j < matrix.cols(); ++j) {
os << matrix(i, j) << " ";
}
os << std::endl;
}
return os;
}
int main() {
Matrix mat(2, 3);
mat(0, 0) = 1.0;
mat(0, 1) = 2.0;
mat(0, 2) = 3.0;
mat(1, 0) = 4.0;
mat(1, 1) = 5.0;
mat(1, 2) = 6.0;
std::cout << mat << std::endl;
return 0;
}
```
运行结果如下:
```
1 2 3
4 5 6
```