Friend functions a few questions

This is a discussion on Friend functions a few questions within the C++ Programming forums, part of the General Programming Boards category; I read that to change access a private constant data member of a class you must declare your member function ...

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    450

    Friend functions a few questions

    I read that to change access a private constant data member of a class you must declare your member function as constant.

    (* The above should read*)
    I read that to access a private constant data member of a class you must declare your member function as constant.

    I think I also remember reading non-member friend functions of a class can not be declared as constant why is this?

    To refresh my memory a little, constant data members must be initialized using a member initializer in the constructor definition correct. Suppose you want to initialize a private data member from a friend function would you use the same notation?
    Last edited by curlious; 08-26-2003 at 04:04 PM.

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    I read that to change access a private constant data member of a class you must declare your member function as constant.

    You cannot change the access of a data member of a class.

    I think I also remember reading non-member friend functions of a class can not be declared as constant why is this?

    No non-member function can be declared const. When you declare a member function constant, it essentially ensures that *this is constant, and there is no this pointer for non-member functions.

    To refresh my memory a little, constant data members must be initialized using a member initializer in the constructor definition correct. Suppose you want to initialize a private data member from a friend function would you use the same notation?

    The best way to find out is to try it out yourself and then examine the results.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 05-05-2008, 11:43 AM
  2. arithmetic operator friend functions
    By linucksrox in forum C++ Programming
    Replies: 7
    Last Post: 02-06-2006, 11:39 PM
  3. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2003, 12:26 AM
  4. Friend functions ?
    By CodeJerk in forum C++ Programming
    Replies: 3
    Last Post: 11-20-2002, 12:46 PM
  5. friend functions
    By The Dog in forum C++ Programming
    Replies: 2
    Last Post: 07-14-2002, 09:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21