[#BloombergLP-bslstl-SharedPtrUtil-dynamicCast-0f]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslstl.adoc[bslstl]::xref:BloombergLP/bslstl/SharedPtrUtil.adoc[SharedPtrUtil]::dynamicCast
:relfileprefix: ../../../
:mrdocs:

Return a `bsl&colon;&colon;shared&lowbar;ptr&lt;TARGET&gt;` object sharing ownership of the same object as the specified `source` shared pointer to the (template parameter) `SOURCE` type, and referring to `dynamic&lowbar;cast&lt;TARGET &ast;&gt;(source&period;get())`&period; If that would return a shared pointer referring to nothing (`0 &equals;&equals; get()`), then instead return an (empty) default constructed shared pointer&period; Note that a compiler diagnostic will be emitted indicating an error unless `dynamic&lowbar;cast&lt;TARGET &ast;&gt;(source&period;get())` is a valid expression&period;&period;

== Synopsis

Declared in `&lt;bslstl&lowbar;sharedptr&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class TARGET,
    class SOURCE&gt;
static
xref:bsl/shared_ptr-0a.adoc[bsl::shared&lowbar;ptr&lt;TARGET&gt;]
dynamicCast(xref:bsl/shared_ptr-0a.adoc[bsl::shared&lowbar;ptr&lt;SOURCE&gt;] const& source) noexcept;
----


[.small]#Created with https://www.mrdocs.com[MrDocs]#
