C++ 运算符错误<&书信电报;重载-找不到运算符

C++ 运算符错误<&书信电报;重载-找不到运算符,c++,compiler-errors,operator-overloading,C++,Compiler Errors,Operator Overloading,我有一个带构造函数的类图,重载的操作符std::cout是std::ostream而不是std::ofstream类型的全局对象std::ofstream是std::ostream的派生版本。看 因此,将您的friend函数(运算符)修改为 friend-ostream&operator class Graph { private: vector<int> setOfVertices; public: Graph(ifstream &a

我有一个带构造函数的类图,重载的
操作符
std::cout
std::ostream
而不是
std::ofstream
类型的全局对象
std::ofstream
是std::ostream
的派生版本。看

因此,将您的friend函数(运算符)修改为

friend-ostream&operator
class Graph
{
    private:
        vector<int> setOfVertices;
    public:
        Graph(ifstream &);      //konstruktor ze souboru
        friend ofstream & operator<<(ofstream&, const Graph &);
};
ofstream & operator<<(ofstream& outputStream, const Graph & graphToPrint)
{
    //not important for minimal example
    return outputStream;
}
#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)
friend ostream & operator<<(ostream&, const Graph &);