this is an example taken from Effective C++ 3ed, it says that if the static_cast
is used this way, the base part of the object is copied, and the call is invoked from that part. I wanted to understand what is happening under the hood, will anyone help?
class Window { // base class
public:
virtual void onResize() { } // base onResize impl
};
class SpecialWindow: public Window { // derived class
public:
virtual void onResize() { // derived onResize impl;
static_cast<Window>(*this).onResize(); // cast *this to Window,
// then call its onResize;
// this doesn't work!
// do SpecialWindow-
} // specific stuff
};
static_cast<Window>(*this)
creates a copy, this code is most likely NOT producing the intended result. – Onetoone