Thread: A treatise on friend is needed

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    45
    Oh, and you might want B's print() to show the inherited part of the object by calling A's print():

    Code:
    class B : public A
    {
        public:
    
            virtual void print (std::ostream & os) const
            {
                 os << "Object of class B. Base: ";
                 A::print (os);
            }
    //...
    In this case, if you decide to hide print() from the clients, you would have to make it protected, not private.

    If I leave print() public, you might argue that my operator<< is just syntax sugar, but... yum! :-)
    Last edited by comocomocomo; 01-02-2013 at 09:11 AM. Reason: Remove unintended smileys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Helping out a friend...
    By rhymewithnothin in forum C Programming
    Replies: 21
    Last Post: 09-15-2005, 08:59 PM
  2. for a friend
    By Ajsan in forum C++ Programming
    Replies: 4
    Last Post: 02-25-2004, 11:04 AM
  3. friend function and friend classes...usage question??
    By actionbasti in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2003, 10:53 PM
  4. friend
    By laasunde in forum C++ Programming
    Replies: 3
    Last Post: 11-30-2002, 10:15 AM