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. The Lounge
  3. member functions vs. non-member functions

member functions vs. non-member functions

Scheduled Pinned Locked Moved The Lounge
visual-studiocomalgorithmsoopquestion
8 Posts 6 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.
  • L Offline
    L Offline
    Li Lirong
    wrote on last edited by
    #1

    Hi, all, What's your opinions on Scott Meyers' article: How Non-Member Functions Improve Encapsulation In that article, he gave the following algorithm: if (f needs to be virtual) { make f a member function of C; } else if (f is operator>> or operator<< ) { make f a non-member function; if (f needs access to non-public members of C) { make f a friend of C; } } else if (f needs type conversions on its left-most argument) { make f a non-member function; if (f needs access to non-public members of C) { make f a friend of C; } else if (f can be implemented via C's public interface) { make f a non-member function; } else { make f a member function of C; } Do you agree with this algorithm? Regards, Lirong

    L N D 3 Replies Last reply
    0
    • L Li Lirong

      Hi, all, What's your opinions on Scott Meyers' article: How Non-Member Functions Improve Encapsulation In that article, he gave the following algorithm: if (f needs to be virtual) { make f a member function of C; } else if (f is operator>> or operator<< ) { make f a non-member function; if (f needs access to non-public members of C) { make f a friend of C; } } else if (f needs type conversions on its left-most argument) { make f a non-member function; if (f needs access to non-public members of C) { make f a friend of C; } else if (f can be implemented via C's public interface) { make f a non-member function; } else { make f a member function of C; } Do you agree with this algorithm? Regards, Lirong

      L Offline
      L Offline
      Larry Antram
      wrote on last edited by
      #2

      Not in the real world. Regards, Larry Antram Stardust Software "Those who choose to sacrifice freedom in order to gain security shall not have, nor do they deserve, either one" -- Benjamin Franklin

      L 1 Reply Last reply
      0
      • L Larry Antram

        Not in the real world. Regards, Larry Antram Stardust Software "Those who choose to sacrifice freedom in order to gain security shall not have, nor do they deserve, either one" -- Benjamin Franklin

        L Offline
        L Offline
        Li Lirong
        wrote on last edited by
        #3

        >Not in the real world. Why? In his articles, Scott gave reasons for his argument --- non-member functions can improve encapsulation. If the reasons are valid, why it is not practical in the real world? If those reasons are not valid, why they are not? Regards, Lirong

        L 1 Reply Last reply
        0
        • L Li Lirong

          >Not in the real world. Why? In his articles, Scott gave reasons for his argument --- non-member functions can improve encapsulation. If the reasons are valid, why it is not practical in the real world? If those reasons are not valid, why they are not? Regards, Lirong

          L Offline
          L Offline
          Larry Antram
          wrote on last edited by
          #4

          Sorry, I was being sarcastic. ;) I don't necissarily disagree with the non-member argument but more the generic algorithm... in particular the importance of "friend" classes in it (which, IMO, have a similar status as "goto"). Regards, Larry Antram Stardust Software "Those who choose to sacrifice freedom in order to gain security shall not have, nor do they deserve, either one" -- Benjamin Franklin

          M 1 Reply Last reply
          0
          • L Larry Antram

            Sorry, I was being sarcastic. ;) I don't necissarily disagree with the non-member argument but more the generic algorithm... in particular the importance of "friend" classes in it (which, IMO, have a similar status as "goto"). Regards, Larry Antram Stardust Software "Those who choose to sacrifice freedom in order to gain security shall not have, nor do they deserve, either one" -- Benjamin Franklin

            M Offline
            M Offline
            Michael Dunn
            wrote on last edited by
            #5

            Larry Antram wrote: in particular the importance of "friend" classes in it (which, IMO, have a similar status as "goto"). I can express this as:

            if (f needs access to non-public members of C)
            {
            Application.design.fix();
            }

            ;) --Mike-- Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm

            L 1 Reply Last reply
            0
            • L Li Lirong

              Hi, all, What's your opinions on Scott Meyers' article: How Non-Member Functions Improve Encapsulation In that article, he gave the following algorithm: if (f needs to be virtual) { make f a member function of C; } else if (f is operator>> or operator<< ) { make f a non-member function; if (f needs access to non-public members of C) { make f a friend of C; } } else if (f needs type conversions on its left-most argument) { make f a non-member function; if (f needs access to non-public members of C) { make f a friend of C; } else if (f can be implemented via C's public interface) { make f a non-member function; } else { make f a member function of C; } Do you agree with this algorithm? Regards, Lirong

              N Offline
              N Offline
              Nemanja Trifunovic
              wrote on last edited by
              #6

              Don't know about the algorithm, but I find the article very, VERY interesting. Now I view encapsulation in a quite another light :) I vote pro drink :beer:

              1 Reply Last reply
              0
              • L Li Lirong

                Hi, all, What's your opinions on Scott Meyers' article: How Non-Member Functions Improve Encapsulation In that article, he gave the following algorithm: if (f needs to be virtual) { make f a member function of C; } else if (f is operator>> or operator<< ) { make f a non-member function; if (f needs access to non-public members of C) { make f a friend of C; } } else if (f needs type conversions on its left-most argument) { make f a non-member function; if (f needs access to non-public members of C) { make f a friend of C; } else if (f can be implemented via C's public interface) { make f a non-member function; } else { make f a member function of C; } Do you agree with this algorithm? Regards, Lirong

                D Offline
                D Offline
                Daniel Turini
                wrote on last edited by
                #7

                He is sooooo right. Actually, on stupid small classes I don't do it, but in every other class I do it and people yell at me that I’m not doing OOP. Now I have a nice argument… Concussus surgo. When struck I rise.

                1 Reply Last reply
                0
                • M Michael Dunn

                  Larry Antram wrote: in particular the importance of "friend" classes in it (which, IMO, have a similar status as "goto"). I can express this as:

                  if (f needs access to non-public members of C)
                  {
                  Application.design.fix();
                  }

                  ;) --Mike-- Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm

                  L Offline
                  L Offline
                  Len Holgate
                  wrote on last edited by
                  #8

                  Michael Dunn wrote: I can express this as: Sometimes yes, sometimes no... Personally I'd like proper ACL's in access specifiers... Len Holgate www.jetbyte.com The right code, right now.

                  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