C++11 introduced the possibility of delegating construction from one constructor to another - "delegating constructors".
But - when doing that, can we use the this pointer? e.g. as an argument to one of the constructors we're delegating to? It's not trivial to assume that we can while the "real constructor" has not actually been invoked yet.
For a definitive answer one would need to read the standard (and even there it might not be entirely clear, see @BenjaminBanner's comment). But in practice - yes, apparently we can use
thisin constructor delegation.The following example:
compiles (GodBolt) with all of GCC, clang and MSVC. They do not warn about doing this, even with
-Wall -Wpedantic -Wextraor/W4for MSVC.It also runs (coliru.com) and produces the expected output (at the link you have the g++-compiled version, clang++ can be checked there as well).