Thread: Friend functions

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    54

    Friend functions

    is it possible for a derived class to have friend functions of a base class?

    Im trying to allow only 2 functions of the derived class access the base classes privates. the base class was inherited publicly.

    I know I could just make mutators functions in the base class, but I want to try doing this without giving main the ability to alter the values simply by calling the base class.
    Last edited by JeremyCAFE; 02-12-2006 at 07:58 PM.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    you could supply accessor functions within protected scope in the base class that the derived class could use, but as far as limiting access to two functions of the derived class I'm not sure if that would be possible. even if it is possible, the solution would likely be complicated and ugly.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    54
    forgot about even using protected. thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Friend Functions
    By rculley1970 in forum C++ Programming
    Replies: 5
    Last Post: 03-25-2007, 03:25 AM
  2. Static member functions more efficient?
    By drrngrvy in forum C++ Programming
    Replies: 6
    Last Post: 06-16-2006, 07:07 AM
  3. Friend template functions
    By lyx in forum C++ Programming
    Replies: 4
    Last Post: 10-02-2003, 01:11 PM
  4. inline friend functions.
    By sean in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2002, 12:37 PM
  5. Visual C++ and friend functions giving errors
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 11-04-2001, 06:55 PM