friend AND inline method, what's the point ?

后端 未结 3 1914

I see in a header that I didn\'t write myself the following:

class MonitorObjectString: public MonitorObject {
   // some other declarations
   friend inlin         


        
3条回答
  •  日久生厌
    2020-11-30 02:48

    Grammatically speaking...

    The friend keyword is still needed to tell the compiler that this function is not a member of a class, EDIT: but instead a non-member function that can see the private members of the class.


    However, this could have been implemented more cleanly like this:

    /* friend */ inline bool operator ==(const MonitorObjectString& rhs) const
    { return fVal == rhs.fVal; }
    

    (Of course, I'm assuming fVal is of a suitable type that can be compared without affecting its const-ness.)

提交回复
热议问题