Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
optional<T>要求这T是一个完整的类型(因此具有已知的大小)。在 classA的定义完成之前,A是一个不完整的类型。因此错误。
optional<T>
T
A
没有办法让任何类型T拥有 type 的成员变量optional<T>,因为optional<T> 它自己有一个 type 的成员变量T。您可以堆分配一个optional<T>(或只是一个T,因为您将存储一个可能是的指针nullptr)。
nullptr