When I have a shared_ptr
to a derived type, but the type of the shared_ptr is to the base type, I cannot see anything but the base type's members in the Locals window of Visual Studio (as if the object was sliced).
Below is a very small program that shows the issue I'm seeing. If a breakpoint is set after the shared_ptr
is constructed, and the variable sp
is viewed in the Locals window, dvalue
cannot be seen.
Is there a way to see this? Perhaps I've been spoiled by managed code...
#include <memory>
struct Base {
int ivalue;
};
struct Derived : public Base {
double dvalue;
};
int main() {
Derived d;
d.ivalue = 42;
d.dvalue = 3.14;
auto sp = std::make_shared<Base>(d);
// break here
return 0;
}