我有一个关于C++11指针的问题。具体来说,如何将一个基类的unique pointer转换为派生类的指针?
class Base
{
public:
int foo;
}
class Derived : public Base
{
public:
int bar;
}
...
std::unique_ptr<Base> basePointer(new Derived);
// now, how do I access the bar member?
这应该是可以实现的,但我无法想出如何做到。每次尝试使用时
basePointer.get()
我最终得到了可执行文件崩溃的结果。
提前感谢,任何建议将不胜感激。
basePointer.get()
肯定不是问题所在。 - jogojapan