CS253

CS253: Software Development with C++

Spring 2018

Friends

See this page as a slide show

CS253 Friends

Friend Declarations

One class can declare another class/method/function to be its friend:

class Foo {
    friend class Bar;                   // an entire class
    friend double Zip::zulu(int) const; // just one method
    friend int alpha();                 // a free function
    friend std::ostream &operator<<(std::ostream &os, const Foo &);
  private:
    int x,y;
};

Restrictions

Don’t go nuts

Modified: 2018-02-06T16:57

User: Guest

Check: HTML CSS
Edit History Source
Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2015 Colorado State University
CS Building