Skip to main content
6 events
when toggle format what by license comment
Mar 20, 2014 at 15:05 comment added Lars Viklund @Guss: I cannot find any chapter and verse for your claim, nor reproduce it in a compiler. C++11 13.5.6/1 indicates that if a suitable overload exists, x->m shall be interpreted as (x.operator->())->m. If the LHS is something that has a suitable overload of operator-> again, this process recurs until there's just the usual (*x).m effect of 5.2.5/2.
Aug 30, 2013 at 1:32 vote accept aaazalea
Apr 14, 2013 at 11:03 comment added Guss @LarsViklund: your answer has a problem: you said "operator-> ... automatically chains operator-> calls until one in the chain returns a raw pointer". This is not correct - using A->B syntax chains at most 1 additional call. What the C++ -> binary syntax actually does is not call the object's opeartor-> directly - instead it looks at the type of A and check if its a raw pointer. If it is then -> derefs it and execute B on that, otherwise it calls the object's operator->, derefs the result (either using native raw pointer or another operator-> and then executes B on the result
Sep 22, 2012 at 18:55 comment added Lars Viklund It illustrates the last paragraph of my answer, how using the -> operator chains until it gets a raw pointer to something, dereferencing and accessing a member of it. If operator -> didn't chain, the example would be ill-formed as a shared_ptr is not a raw pointer.
Sep 21, 2012 at 19:48 comment added Trevor Hickey What does your example illustrate? Are you returning a smart pointer to a string and somehow outputting the size? I'm confused.
Jul 19, 2012 at 15:23 history answered Lars Viklund CC BY-SA 3.0