Fundamental question about visibility

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Casper Bang

    #16
    Re: Fundamental question about visibility

    Adding custom constructors for passing of desired objects works but is not
    exactly an elegant solution.
    I solved it with the suspected GetParent call:

    ((<DerivedClass >)GetParent()). <MemberName>
    ^
    Returns base class!

    ....but I had to cast to the overidden class and NOT rely on C++ to know
    this! I would've thought GetParent pointed to the new class and not the old
    but maybe this is simply a MFC specific twist. One more lesson learned!

    Thanks for the feedback,
    Casper

    ----------

    "WW" <wolof@freemail .hu> wrote in message
    news:bkqp6e$c2n $1@phys-news1.kolumbus. fi...[color=blue]
    > WW wrote:
    > [SNIP]
    > Update
    >[color=green]
    > > // Overide the CEdit class so we can capture CTRL + ENTER events
    > > class CModifiedEdit : public CEdit
    > > {
    > > CMainWindow *parent;[/color]
    >
    > Here I hope a *lot* that CEdit does have a virtual destructor. In our[/color]
    case[color=blue]
    > it does not really matter (there is no descruction for a pointer and[/color]
    Windows[color=blue]
    > will release the memory properly) but according to Standard C++ it is[/color]
    better[color=blue]
    > be there. (Also in your code CMainWindow will always destroy[/color]
    CModifiedEdit[color=blue]
    > as CModifiedEdit, but later if you go dynamic about the GUI it might not[/color]
    be[color=blue]
    > the case.)
    >[color=green]
    > > public:
    > > CModifiedEdit(C MainWindow *mamma) : parent(mamma) { ; }
    > > afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
    > > };[/color]
    > [SNIP]
    > --
    > WW aka Attila
    >
    >[/color]


    Comment

    • WW

      #17
      Re: Fundamental question about visibility

      Casper Bang wrote:[color=blue]
      > Adding custom constructors for passing of desired objects works but
      > is not exactly an elegant solution.
      > I solved it with the suspected GetParent call:
      >
      > ((<DerivedClass >)GetParent()). <MemberName>
      > ^
      > Returns base class!
      >
      > ...but I had to cast to the overidden class and NOT rely on C++ to
      > know this! I would've thought GetParent pointed to the new class and
      > not the old but maybe this is simply a MFC specific twist. One more
      > lesson learned![/color]

      Don't top post! I will not suggest using templates to someone possibly
      using VC++ 6.0.

      --
      WW aka Attila


      Comment

      • jeffc

        #18
        Re: Fundamental question about visibility


        "WW" <wolof@freemail .hu> wrote in message
        news:bksfn7$bei $1@phys-news1.kolumbus. fi...[color=blue][color=green]
        > >
        > > I'll let you read about it "The C++ Programming Language" by Bjarne
        > > Stroustrup. In the meantime, if you can possibly be any more
        > > pedantic, please do. It would amaze me.[/color]
        >
        > You mean the quote that some people, sometimes may call virtual member
        > functions methods? A very widely accepted definition. See the original
        > post of this thread.[/color]

        I don't need to look past the post that said "There are no methods in C++."
        [color=blue]
        > If you choose to use a vague and confusing term (with no exact definition)
        > by all means do it. But then do not wonder if people think you are not[/color]
        here[color=blue]
        > to help.[/color]

        Riiiiiiight, Mr. Pedant. No one had a problem with the OP's question except
        you. Now, who wasn't here to help, but to display his dictionary knowledge
        of the C++ language?


        Comment

        • Shane Beasley

          #19
          Re: Fundamental question about visibility

          "WW" <wolof@freemail .hu> wrote in message news:<bksbbe$se 3$1@phys-news1.kolumbus. fi>...
          [color=blue]
          > Please, if you *know* what method means in the realm of the C++ language...
          > by all means, post it here![/color]

          <http://www.nightflight .com/foldoc-bin/foldoc.cgi?meth od>

          "The name given in Smalltalk and other object-oriented languages to a
          procedure or routine associated with one or more classes. An object of
          a certain class knows how to perform actions, e.g. printing itself or
          creating a new instance of itself, rather than the function (e.g.
          printing) knowing how to handle different types of object."

          Sounds like a virtual function to me. Actually, FOLDOC also mentions
          the concept of a "class method" -- that's a static member function, of
          course.

          Given this, one might say that it is incorrect to use "method" to
          describe a non-virtual member function, although I have yet to find
          any such use to be confusing or misleading, so I don't even bother
          bringing that up. I might almost mention it if a non-member function
          were called a method, though.

          - Shane

          Comment

          • WW

            #20
            Re: Fundamental question about visibility

            jeffc wrote:[color=blue]
            > "WW" <wolof@freemail .hu> wrote in message
            > news:bksfn7$bei $1@phys-news1.kolumbus. fi...[color=green][color=darkred]
            >>>
            >>> I'll let you read about it "The C++ Programming Language" by Bjarne
            >>> Stroustrup. In the meantime, if you can possibly be any more
            >>> pedantic, please do. It would amaze me.[/color]
            >>
            >> You mean the quote that some people, sometimes may call virtual
            >> member functions methods? A very widely accepted definition. See
            >> the original post of this thread.[/color]
            >
            > I don't need to look past the post that said "There are no methods in
            > C++."[/color]

            Again: you refer to TC++PL for what method means. That says: *some* call
            virtual member functions methods. My proof: look at what the OPs original
            post and realise that he was *not* using method in the sense Mr. Stroustrup
            says *some* (apparently other) people do.

            Stop trolling.
            [color=blue][color=green]
            >> If you choose to use a vague and confusing term (with no exact
            >> definition) by all means do it. But then do not wonder if people
            >> think you are not here to help.[/color]
            >
            > Riiiiiiight, Mr. Pedant.[/color]

            Please read my name Mr. Infantile. It is not Mr. Pedant. Stop trolling.
            [color=blue]
            > No one had a problem with the OP's question
            > except you.[/color]

            I had no problem with the question. I have answered it. Stop trolling.
            [color=blue]
            > Now, who wasn't here to help, but to display his
            > dictionary knowledge of the C++ language?[/color]

            And what are you here for? To get into every thread and try to attack me
            because you think it is cool? Stop trolling. You help none, on the
            contrary.

            BTW NICE SNIPPING! How come you have snipped out that Steve Dewhurst's book
            (C++ Gothcas) exactly my advice: do not use the word method in C++
            discussions? Ah. Because that was showing that all you do is troll to
            practice your ego.

            The OP had no problem with my advice. The OP was (instead of you) showing
            no attitude and has got answer to his questions. So why don't you get lost
            for ever? It is clear you do not have the mental capacity to help, so you
            troll. No need for that. Find another place where you can scream and
            wallow on the ground to get into the center of attention. Stop trolling.

            --
            WW aka Attila


            Comment

            • WW

              #21
              Re: Fundamental question about visibility

              Shane Beasley wrote:[color=blue]
              > "WW" <wolof@freemail .hu> wrote in message
              > news:<bksbbe$se 3$1@phys-news1.kolumbus. fi>...
              >[color=green]
              >> Please, if you *know* what method means in the realm of the C++
              >> language...
              >> by all means, post it here![/color]
              >
              > <http://www.nightflight .com/foldoc-bin/foldoc.cgi?meth od>
              >
              > "The name given in Smalltalk and other object-oriented languages to a
              > procedure or routine associated with one or more classes. An object of
              > a certain class knows how to perform actions, e.g. printing itself or
              > creating a new instance of itself, rather than the function (e.g.
              > printing) knowing how to handle different types of object."
              >
              > Sounds like a virtual function to me. Actually, FOLDOC also mentions
              > the concept of a "class method" -- that's a static member function, of
              > course.
              >
              > Given this, one might say that it is incorrect to use "method" to
              > describe a non-virtual member function, although I have yet to find
              > any such use to be confusing or misleading, so I don't even bother
              > bringing that up. I might almost mention it if a non-member function
              > were called a method, though.[/color]

              Method has no definition in a C++ discussion. It can only cause
              imprecision, confusion and misunderstandin g.

              --
              WW aka Attila


              Comment

              • Gavin Deane

                #22
                Re: Fundamental question about visibility

                "jeffc" <nobody@nowhere .com> wrote in message news:<3f71e1d0_ 4@news1.prserv. net>...[color=blue]
                > "WW" <wolof@freemail .hu> wrote in message
                > news:bksfn7$bei $1@phys-news1.kolumbus. fi...[color=green]
                > > If you choose to use a vague and confusing term (with no exact definition)
                > > by all means do it. But then do not wonder if people think you are not[/color]
                > here[color=green]
                > > to help.[/color]
                >
                > Riiiiiiight, Mr. Pedant. No one had a problem with the OP's question except
                > you. Now, who wasn't here to help, but to display his dictionary knowledge
                > of the C++ language?[/color]

                How do you know how many other people also had an objection to the use
                of 'method' but elected not to mention it after WW had already brought
                it up?

                And how does the exchange between the OP and WW which ended with the
                OP's problem solved lead you to conclude that WW wasn't helping?

                Comment

                • Attila Feher

                  #23
                  Re: Fundamental question about visibility

                  Gavin Deane wrote:
                  [SNIP][color=blue][color=green]
                  >> Riiiiiiight, Mr. Pedant. No one had a problem with the OP's
                  >> question except you. Now, who wasn't here to help, but to display
                  >> his dictionary knowledge of the C++ language?[/color]
                  >
                  > How do you know how many other people also had an objection to the use
                  > of 'method' but elected not to mention it after WW had already brought
                  > it up?
                  >
                  > And how does the exchange between the OP and WW which ended with the
                  > OP's problem solved lead you to conclude that WW wasn't helping?[/color]

                  He does not conclude. He prejudges.

                  --
                  Attila aka WW


                  Comment

                  • jeffc

                    #24
                    Re: Fundamental question about visibility


                    "WW" <wolof@freemail .hu> wrote in message
                    news:bktoeu$58i $1@phys-news1.kolumbus. fi...[color=blue]
                    >
                    > BTW NICE SNIPPING! How come you have snipped out that Steve Dewhurst's[/color]
                    book[color=blue]
                    > (C++ Gothcas) exactly my advice: do not use the word method in C++
                    > discussions? Ah. Because that was showing that all you do is troll to
                    > practice your ego.[/color]

                    Because you're a pedant.


                    Comment

                    • jeffc

                      #25
                      Re: Fundamental question about visibility


                      "Gavin Deane" <deane_gavin@ho tmail.com> wrote in message
                      news:6d8002d0.0 309250324.4205c b1@posting.goog le.com...[color=blue]
                      >
                      > How do you know how many other people also had an objection to the use
                      > of 'method' but elected not to mention it after WW had already brought
                      > it up?[/color]

                      I'd argue with all the pedants. Anyone who wastes a post telling someone
                      else that "method is not part of the C++ standard language! nyah nyah!" has
                      a stick way too far up their rear.


                      Comment

                      • jeffc

                        #26
                        Re: Fundamental question about visibility


                        "WW" <wolof@freemail .hu> wrote in message
                        news:bktoi1$591 $1@phys-news1.kolumbus. fi...[color=blue]
                        >
                        > Method has no definition in a C++ discussion. It can only cause
                        > imprecision, confusion and misunderstandin g.[/color]

                        Yeah, right.


                        Comment

                        • jeffc

                          #27
                          Re: Fundamental question about visibility


                          "Gavin Deane" <deane_gavin@ho tmail.com> wrote in message
                          news:6d8002d0.0 309250324.4205c b1@posting.goog le.com...[color=blue]
                          > And how does the exchange between the OP and WW which ended with the
                          > OP's problem solved lead you to conclude that WW wasn't helping?[/color]

                          The part about the method was completely unhelpful. He was just saying it
                          to show off his book knowledge of detail unrelated to the question, so he
                          can appear authoritative, toe the party line, be part of the cool C++ geek
                          crowd, and waste space in the newsgroup. People like that are only
                          motivated partially by helping people. Terms like method are completely
                          valid when discussing C++ design and code, regardless of whether the word
                          appears in the C++ keyword list, or even the official standard. Just like
                          base class, parent class, and superclass can be used interchangably, even
                          though you won't find them in the language. Unlike some people, I'm not
                          sitting here with a steel rod up my butt waiting for the next time someone
                          uses the term superclass so I can pounce on them for using a word that
                          doesn't exist in the language.


                          Comment

                          • Noah Roberts

                            #28
                            Re: Fundamental question about visibility

                            WW wrote:[color=blue]
                            > jeffc wrote:
                            >[color=green]
                            >>"WW" <wolof@freemail .hu> wrote in message
                            >>news:bkqkn3$5 ld$1@phys-news1.kolumbus. fi...
                            >>[color=darkred]
                            >>>Casper Bang wrote:
                            >>>
                            >>>>My question is fundamental I beleive but it has been teasing me for
                            >>>>a while:
                            >>>>
                            >>>>I have two classes in my app. The first class is instantiated as a
                            >>>>member of my second class. Within this first class, a method (event)
                            >>>>needs to be able to invoke methods of the second class.
                            >>>
                            >>>There are no methods in C++. There are member functions.[/color]
                            >>
                            >>Oh brother. <warning>Pedant Police<warning>[/color]
                            >
                            >
                            > Please, if you *know* what method means in the realm of the C++ language...
                            > by all means, post it here!
                            >[/color]

                            Methods are actions you may request that an object carry out. You
                            invoke 'methods' by passing 'messages'; methods are implementations of
                            messages. This is basic OO terminology that you learn in any
                            introductory text.

                            The problem with C++ is that when you pass a message to an object it is
                            not necissarily the one that carries out the action even if it has
                            overridden its parent's methods. This is only guaranteed if the method
                            is declaired virtual in *all* parents. I suppose this is why some
                            people would consider only virtual 'functions' to be methods and why
                            others would object to a "member function" being called a method at all.
                            This is also one of the reasons I find C++ does not quite apply the OO
                            paradigm (which can be a strength at times).

                            There is also the fact that all C++ "member functions" eventually get
                            altered to in fact be functions that accept class structs as arguments.
                            I myself don't believe this should have an impact on our terminology
                            as it is an implementation detail that the programmer never really sees.
                            In other OO languages the term method is used and they also get
                            altered by the compiler to have a more function like signature. For
                            example Objective-C works this way (many even just preprocess into C)
                            but we use OO terms not procedural terms.

                            In my opinion the *only* reason to call a method "member function" is
                            because it is what C++ programmer terminology uses; and of course
                            because there are some who will pretend not to know what you mean, go
                            off on some rant, and may never answer the question. The term
                            "function" is really not an OO concept and, in my opinion, it is a
                            mistake to use it as such.

                            NR

                            Comment

                            • jeffc

                              #29
                              Re: Fundamental question about visibility


                              "Noah Roberts" <nroberts@donte mailme.com> wrote in message
                              news:3F73070B.1 0000@dontemailm e.com...[color=blue]
                              >
                              > Methods are actions you may request that an object carry out. You
                              > invoke 'methods' by passing 'messages'; methods are implementations of
                              > messages. This is basic OO terminology that you learn in any
                              > introductory text.
                              >
                              > The problem with C++ is that when you pass a message to an object it is
                              > not necissarily the one that carries out the action even if it has
                              > overridden its parent's methods. This is only guaranteed if the method
                              > is declaired virtual in *all* parents. I suppose this is why some
                              > people would consider only virtual 'functions' to be methods and why
                              > others would object to a "member function" being called a method at all.
                              > This is also one of the reasons I find C++ does not quite apply the OO
                              > paradigm (which can be a strength at times).
                              >
                              > There is also the fact that all C++ "member functions" eventually get
                              > altered to in fact be functions that accept class structs as arguments.
                              > I myself don't believe this should have an impact on our terminology
                              > as it is an implementation detail that the programmer never really sees.
                              > In other OO languages the term method is used and they also get
                              > altered by the compiler to have a more function like signature. For
                              > example Objective-C works this way (many even just preprocess into C)
                              > but we use OO terms not procedural terms.
                              >
                              > In my opinion the *only* reason to call a method "member function" is
                              > because it is what C++ programmer terminology uses; and of course
                              > because there are some who will pretend not to know what you mean, go
                              > off on some rant, and may never answer the question.[/color]

                              Now that is the voice of reason. Having said all that, it's pretty clear
                              why we don't have to post a whole page like this just because someone in
                              this newsgroup uses the term "method".


                              Comment

                              • WW

                                #30
                                Re: Fundamental question about visibility

                                jeffc wrote:[color=blue]
                                > "WW" <wolof@freemail .hu> wrote in message
                                > news:bktoeu$58i $1@phys-news1.kolumbus. fi...[color=green]
                                >>
                                >> BTW NICE SNIPPING! How come you have snipped out that Steve
                                >> Dewhurst's book (C++ Gothcas) exactly my advice: do not use the word
                                >> method in C++ discussions? Ah. Because that was showing that all
                                >> you do is troll to practice your ego.[/color]
                                >
                                > Because you're a pedant.[/color]

                                Stop trolling.

                                --
                                WW aka Attila


                                Comment

                                Working...