The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

michele.orsini (1) [Avatar] Offline
First of all: Nishant, your book is great and it is a pleasure reading it.
I found a point that I did not understand in chap 4, in CAutoNativePtr class implementation.

I wonder why operator-> and operator T* are declared static in the above class, I tried to remove the static keyword and the example failed to compile.
In particular, removing static keyword from operator T*, compiler error is:
error C2440: 'return' : cannot convert from 'Native' to 'AutoNativePtr<T> %'
in the "return *this statement" of the operator= member function.

It is "as if" compiler applied operator T* to *this expression, while using the static keyword this does not happen, as if some sort of "precedence" is applied to non static member function to solve a syntactic conflict.

In standard C++, it is frequent to have smart pointer classes with both T* operator and a "return *this" statement in his assignment operator.
Does it means that every time assignment operator of these smart pointer is at work a "nude" pointer is returned and a smart pointer constructor is implicitly invoked?
Can you please shed some light on this point please?