Ugh. This is one example of "never do this." In dostuffyou create a temporary type derclass, take its address and delete it outside dostuff(assigning it basec). As soon as the line creating the temporary one is finished, access to it through this pointer gives undefined behavior. The fact that it works (i.e. your program prints "wtf") certainly depends on the platform.
? , , ++. derclass. ? , . ( ) .
, , . , . - , (, , "wtf", - ), .
-, dostuff printf. , , factorial(10) . , printf .