当我编译引用 std::ostream 时,我有一个奇怪的错误弹出
I have a weird error that pops up when I compile referring to std::ostream
这个错误对我来说毫无意义,我以前做过这样的事情,并跟随它到发球台,但现在它只是弹出。
#ifndef MATRICA_HPP_INCLUDED
#define MATRICA_HPP_INCLUDED
#include <iostream>
#include <cstdio>
#define MAX_POLJA 6
using namespace std;
class Matrica {
private:
short int **mtr;
short int **ivicaX;
short int **ivicaY;
int lenX, lenY;
public:
Matrica(short int, short int);
~Matrica();
int initiate_edge(const char *, const char *);
short int get_vrednost (short int, short int) const;
short int operator = (const short int);
int check_if_fit(int *);
friend ostream& operator << (ostream&, const Matrica&) const; // HAPPENS HERE <====
};
#endif // MATRICA_HPP_INCLUDED
这是错误:
error: non-member function 'std::ostream& operator<<(std::ostream&, const Matrica&)' cannot have cv-qualifier|
friend ostream& operator << (ostream&, const Matrica&) const;
您将ostream& operator << (ostream&, const Matrica&)
声明为 friend
,这使它成为一个自由函数,而不是一个成员函数。自由函数没有 this
指针,它受到函数声明末尾const
修饰符的影响。这意味着如果你有一个自由函数,你不能让它成为一个const
函数,因为没有this
指针受它的影响。只需像这样删除它:
friend ostream& operator << (ostream&, const Matrica&);
你准备好了。
相关文章:
- VSCode-有一个红色下划线,但程序构建和运行正确,并且出现配音错误
- 我在 .h 中有一个枚举类,并且在.cpp错误中有一个运算符重载:与"运算符<<不匹配
- 我有一个线程 1:EXC_BAD_ACCESS(代码 = 1,地址 = 0x8)错误.我认为这是由于内存管理不好.我可以
- 处理程序的模块列表中有一个错误的模块"WebSocketModule"
- 编译器错误:函数调用在常量表达式中必须有一个常量值
- LNK2001尝试将我的主函数分离为主.cpp时,我有一个奇怪的错误
- 为什么有一个指向此代码行(第 7 行)的"no matching call for function"错误?
- 我在咖啡中添加了一个新层,但有一个关于"layer_param_"的错误
- 我在 c ++ 中有一个循环错误
- 为什么第三板有一个错误
- 我在代码中有一个错误,错误是:(智能感知:不允许抽象类类型"HourlyWorker"的对象:)
- 错误:在“(”标记之前进行预期的构造函数、析构函数或类型转换.即使我有一个构造函数
- 带有显式构造函数的智能指针使我有一个错误
- 我有一个与Irrlicht创建Cmakelist的错误
- 我的基本C 程序中有一个未指定的错误
- 它不是编译.我正在调用一个通过引用调用的函数,但有一个错误,无法将双*转换为双倍
- 得到错误"left of '.toString' must have class/struct/union",即使 toString 应该有一个合适的对象
- 我的调试器说我有一个隔离错误错误,但无法告诉我在哪里,在非常特殊的情况下发生
- 删除指向排序的字符串阵列的指针会在运行后会有一个错误
- 当我编译引用 std::ostream 时,我有一个奇怪的错误弹出