Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. confused about the friend keyword

confused about the friend keyword

Scheduled Pinned Locked Moved C / C++ / MFC
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    markt 0
    wrote on last edited by
    #1

    i understand that the use of the friend keyword allows you to get around access specifiers but im a little confused as to why, or when you would want to do this as opposed to just adding it as a regular function.

    B 1 Reply Last reply
    0
    • M markt 0

      i understand that the use of the friend keyword allows you to get around access specifiers but im a little confused as to why, or when you would want to do this as opposed to just adding it as a regular function.

      B Offline
      B Offline
      bob16972
      wrote on last edited by
      #2

      friend is useful when you build a set of classes that really work together but make more sense to keep as individual classes for organizational reasons. Some of the functionality they use between them should be non-public. Friend helps achieve that. Purists discourage the use of friend. However, that philosophy can lead to huge monolithic classes or exposed public methods that really shouldn't be used by everyone. I found it to be useful but I agree with some that it should be used sparingly.

      M 1 Reply Last reply
      0
      • B bob16972

        friend is useful when you build a set of classes that really work together but make more sense to keep as individual classes for organizational reasons. Some of the functionality they use between them should be non-public. Friend helps achieve that. Purists discourage the use of friend. However, that philosophy can lead to huge monolithic classes or exposed public methods that really shouldn't be used by everyone. I found it to be useful but I agree with some that it should be used sparingly.

        M Offline
        M Offline
        markt 0
        wrote on last edited by
        #3

        Thanks, i think i understand what your saying.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups