I have a GolfCourse class header gcourse.hh and I want to implement operator overload for >>operator. How do I do this outside the header in file gcourse.cc? That is, which “words” do I need to point to the class itself, “GolfCourse::” is not enough like for functions…?
gcourse.hh:
class GolfCourse {
public:
---
friend std::istream& operator>> (std::istream& in, GolfCourse& course);
gcourse.cc:
---implement operator>> here ---
GolfCourse::is incorrect becauseoperator >>isn’t a member ofGolfCourse. It’s a free function. You’d just need to write:The
frienddeclaration in the class definition is only needed if you plan to accessprivateorprotectedmembers fromGolfCourse. You can, of course, provide the implementation inside the class definition: