~/lightning

Smart Pointers in C++ Are Not Pointers

Lightningat ACCU 2024 · 2024-04-17..04-20· [c-and-cpp]
links:none on file
slides:none on file

Explains that raw pointers and references support covariant returns but smart pointers do not because unique_ptr is a class not a built in pointer type so overriding a virtual that returns std::unique_ptr<Super> with std::unique_ptr<Sub> fails to compile. Shows small code example demonstrating the compile error and the simple workaround of providing an overload that returns the concrete smart pointer type. Notes this is a language limitation not a design flaw.

AI-written summary · about

~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.