0
我有2個類,我想返回一個私有成員對象的引用。unique_ptr:所以我不能再引用已刪除的函數
class BB{};
class B
{
std::unique_ptr<BB> b;
public:
const std::unique_ptr<BB>& getBB(){return b;}
};
int main()
{
B b;
std::unique_ptr<BB> x=b.getBB();
}
毫無疑問,在x=b.GetBB()
,說 ...can't be referenced. It's a deleted function.
請問您能否發佈完整的錯誤? – RedX 2015-03-03 07:35:16
離開'std :: unique_ptr b;'未初始化的不是默認構造的'BB'使btw,除非你遺漏了'B'的構造函數。 –
aruisdante
2015-03-03 07:36:59