1
我有一个类图与构造函数和重载operator <<
,graph.h
:错误操作符<<重载 - 没有操作员发现
class Graph
{
private:
vector<int> setOfVertices;
public:
Graph(ifstream &); //konstruktor ze souboru
friend ofstream & operator<<(ofstream&, const Graph &);
};
构造函数的定义(小例子,并不重要)和运营商< <在分隔文件graph.cpp
:
ofstream & operator<<(ofstream& outputStream, const Graph & graphToPrint)
{
//not important for minimal example
return outputStream;
}
当我打电话operator <<
在main.cpp
:
#include <iostream>
#include <fstream>
#include "graph.h"
using namespace std;
int main()
{
ifstream myFile ("example.txt");
Graph * G = new Graph(myFile);
cout << *G;
return 0;
}
我得到一个错误
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'Graph' (or there is no acceptable conversion)
我没管理由自己来定位代码的错误,我会感谢所有的建议。