Request Short Link
C++ 98
C++ 11
C++ 14
C++ 17
C++ 20
C++ 23
C++ 2c
for-loops as while-loops
array subscription
Show all implicit casts
Show all template parameters of a CallExpr
Use libc++
Transform std::initializer_list
Show noexcept internals
Show padding information
Show coroutine transformation
Show C++ to C transformation
Show object lifetime
Default
15
18
20
22
26
More
GitHub
Patreon
Issues
About
Policies
Examples
C++ Insights @ YouTube
Settings
Version
Need in-house C++ training? Learn more here
×
Made by
Andreas Fertig
Powered by
Flask
and
CodeMirror
Source:
#include <memory> #include <iostream> class Base { public: int x; virtual ~Base(){}; }; class Bases { public: int x; }; class Derived : public Base { public: Derived(int y):y(y){} int y; virtual ~Derived(){}; }; int main() { Derived t{ 1 }; std::shared_ptr<Base> basePtr = std::make_shared<Base>(t); std::shared_ptr<Derived> dPtr = std::dynamic_pointer_cast<Derived>(basePtr); if (dPtr)std::cout << " " << dPtr->y << std::endl; else std::cout << "Failed " << std::endl; Derived tt{ 2 }; Base ttt(tt); std::cout << " " << ttt.x << std::endl; return 0; }
Insight:
Console: