Thread: Query regarding Overloading Address-of Operator

  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
    Ireland
    Posts
    8,446
    Well... I'm glad I came close.
    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
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    :champ: But I was right. Unfortunately I type slow.

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

    You just dwadle around enjoying seeing us frying our brains before you step in.
    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,895
    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

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, 03:08 PM
  2. operator overloading
    By blue_gene in forum C++ Programming
    Replies: 6
    Last Post: 04-29-2004, 04:06 PM
  3. operator overloading
    By dP munky in forum C++ Programming
    Replies: 14
    Last Post: 04-18-2003, 11:45 AM
  4. Operator overloading MSVC++
    By AeroHammer in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2003, 01:40 AM
  5. Full operator overloading in BCB5
    By Mario in forum C++ Programming
    Replies: 5
    Last Post: 06-01-2002, 02:15 PM