Address-of operator

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

    Address-of operator

    What does it mean that "C++ silently write and call address-of operators"?


  • Andrey Tarasevich

    #2
    Re: Address-of operator

    Stub wrote:[color=blue]
    > What does it mean that "C++ silently write and call address-of operators"?[/color]

    It doesn't seem to mean anything. Why don't you provide the complete
    context for this fragment?

    --
    Best regards,
    Andrey Tarasevich

    Comment

    • Nilesh

      #3
      Re: Address-of operator

      "Stub" <stub@asof.co m> wrote in message news:<yXmqb.290 24$Ec1.2667822@ bgtnsc05-news.ops.worldn et.att.net>...[color=blue]
      > What does it mean that "C++ silently write and call address-of operators"?[/color]

      It means that you do not have to explicitally write 'operator &', just
      as you dont have to write 'operator ='. C++ will silently provide its
      own implementation.

      Regards,
      Nilesh Dhakras

      Comment

      • Ron Natalie

        #4
        Re: Address-of operator


        "Nilesh" <dhakras_n@hotm ail.com> wrote in message news:ae9adc7c.0 311060352.2b7d8 e21@posting.goo gle.com...[color=blue]
        > "Stub" <stub@asof.co m> wrote in message news:<yXmqb.290 24$Ec1.2667822@ bgtnsc05-news.ops.worldn et.att.net>...[color=green]
        > > What does it mean that "C++ silently write and call address-of operators"?[/color]
        >
        > It means that you do not have to explicitally write 'operator &', just
        > as you dont have to write 'operator ='. C++ will silently provide its
        > own implementation.
        >[/color]
        Actually that is not true. No implementation is provided by default.
        & is just one of those operators that has a native meaning when not
        overloaded. This is distinct from the copy assignment operator which
        when not declared is implicitly generated.

        This is a subtle distinction but examine the following program:

        #include <iostream>
        using namespace std;

        struct B {
        B* operator&() {
        cout << "B::operator&() \n";
        return this;
        }
        };

        struct D : B {
        };

        int main() {
        D d;
        &d;
        return 0;
        }

        In this case the &d expression invokes the inheritted B::operator&. If there was an implicitly
        generated one (as C++ does for operator=), then the one in B would be hidden and not used.




        Comment

        • Andrey Tarasevich

          #5
          Re: Address-of operator


          Nilesh wrote:[color=blue]
          > "Stub" <stub@asof.co m> wrote in message news:<yXmqb.290 24$Ec1.2667822@ bgtnsc05-news.ops.worldn et.att.net>...[color=green]
          >> What does it mean that "C++ silently write and call address-of operators"?[/color]
          >
          > It means that you do not have to explicitally write 'operator &', just
          > as you dont have to write 'operator ='. C++ will silently provide its
          > own implementation.[/color]

          No, there's absolutely nothing in common between copy assignment
          operator and operator '&' in this respect. C++ does not "provide its own
          implementation" for member operator &, silently or not.

          --
          Best regards,
          Andrey Tarasevich

          Comment

          • wogston

            #6
            Re: Address-of operator

            > No, there's absolutely nothing in common between copy assignment[color=blue]
            > operator and operator '&' in this respect. C++ does not "provide its own
            > implementation" for member operator &, silently or not.[/color]

            I thought it does, unless you define own = operator, copy the members using
            their respective = operators. What is the correct wording of this? Seems
            that is the only thing you disagree about as far as I can tell.

            -w-


            Comment

            • Andrey Tarasevich

              #7
              Re: Address-of operator

              wogston wrote:
              [color=blue][color=green]
              >> No, there's absolutely nothing in common between copy assignment
              >> operator and operator '&' in this respect. C++ does not "provide its own
              >> implementation" for member operator &, silently or not.[/color]
              >
              > I thought it does, unless you define own = operator, copy the members using
              > their respective = operators. What is the correct wording of this? Seems
              > that is the only thing you disagree about as far as I can tell.
              > ...[/color]

              I'm talking about 'operator &'. Once again, C++ does not "provide its
              own implementation" for member 'operator &', silently or not.

              As for the copy assignment operator, you are right. If you don't declare
              one in your class, the compiler will implicitly declare one for you (and
              define it, if necessary and possible).

              --
              Best regards,
              Andrey Tarasevich

              Comment

              • Nilesh

                #8
                Re: Address-of operator

                "Ron Natalie" <ron@sensor.com > wrote in message news:<3faa65c6$ 0$75676$9a6e19e a@news.newshost ing.com>...[color=blue]
                > "Nilesh" <dhakras_n@hotm ail.com> wrote in message news:ae9adc7c.0 311060352.2b7d8 e21@posting.goo gle.com...[color=green]
                > > "Stub" <stub@asof.co m> wrote in message news:<yXmqb.290 24$Ec1.2667822@ bgtnsc05-news.ops.worldn et.att.net>...[color=darkred]
                > > > What does it mean that "C++ silently write and call address-of operators"?[/color]
                > >
                > > It means that you do not have to explicitally write 'operator &', just
                > > as you dont have to write 'operator ='. C++ will silently provide its
                > > own implementation.
                > >[/color]
                > Actually that is not true. No implementation is provided by default.
                > & is just one of those operators that has a native meaning when not
                > overloaded. This is distinct from the copy assignment operator which
                > when not declared is implicitly generated.
                >[/color]

                Thanks Ron for this clarification.

                Nilesh Dhakras.

                Comment

                Working...