这个错误对我来说毫无意义,我以前做过这样的事情,然后一直跟着它到发球台,但现在它突然出现了。
#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&);
你准备好了。
关于c++ - 当我引用 std::ostream 进行编译时,会弹出一个奇怪的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47288998/