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)
我沒管理由自己來定位代碼的錯誤,我會感謝所有的建議。