Query regarding Overloading Address-of Operator

This is a discussion on Query regarding Overloading Address-of Operator within the C++ Programming forums, part of the General Programming Boards category; Read what the God Of C++ (Stroustrup) had to say: Code: int main() { X ob; X *prt = &ob; ...

  1. #16
    Registered User
    Join Date
    Dec 2002
    Posts
    103
    Read what the God Of C++ (Stroustrup) had to say:

    Code:
    int main()
    {
         X ob;
         X *prt = &ob;
    
    // implies ==> X* ptr = ob.X::operator&() // which implies ==> X* prt = X::operator&(&ob); // My question is since the call to operator& member function must pass the // address of the calling object, logically shouldn't this result in a recursive call.
    No. You get the address from "this"; that doesn't involve a call of operator&(). The operator&() you define affects only explicit uses of &. Also, you be careful about making assumptions about what the compiler does. No global function called operator&() will be generated here. If it didn't you might get some "interesting" overload problems. // I would like to understand how does it work ??? or rather why it works return 0; }
    regards,
    Shiv
    Have a wonderful day.... and keep smiling... you look terrific that way
    signing off...
    shiv... as i know him

  2. #17
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,581
    Well... I'm glad I came close.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #18
    Registered User
    Join Date
    Dec 2002
    Posts
    103
    Yes you did .. came very close

    Shiv
    Have a wonderful day.... and keep smiling... you look terrific that way
    signing off...
    shiv... as i know him

  4. #19
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,762
    :champ: But I was right. Unfortunately I type slow.

  5. #20
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,581
    liar.

    You just dwadle around enjoying seeing us frying our brains before you step in.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #21
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    The short version is that the compiler, for its internal operation (such as generating the this pointer) doesn't give a damn about what code you wrote
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Overloading -> operator
    By Hunter2 in forum C++ Programming
    Replies: 0
    Last Post: 05-10-2004, 04:08 PM
  2. operator overloading
    By blue_gene in forum C++ Programming
    Replies: 6
    Last Post: 04-29-2004, 05:06 PM
  3. operator overloading
    By dP munky in forum C++ Programming
    Replies: 14
    Last Post: 04-18-2003, 12:45 PM
  4. Operator overloading MSVC++
    By AeroHammer in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2003, 02:40 AM
  5. Full operator overloading in BCB5
    By Mario in forum C++ Programming
    Replies: 5
    Last Post: 06-01-2002, 03:15 PM

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