我正在构建一个C++库。我有一个struct
,其中包含std::unique_ptr
到另一个struct
,我想从用户隐藏。我可以忽略头文件中智能指针的类型参数吗?
例如:
struct MyStruct {
int x;
private:
std::unique_ptr<MyPrivateStruct> y;
};
现在,我需要在头文件中,用户可以包括,让他们知道它的布局指定MyStruct
。但是,这要求我也公开头MyPrivateStruct
,我不想这样做。由于unique_ptr
的大小是相同的,无论类型如何,是否可以做这样的事情?
struct MyStruct {
int x;
private:
std::unique_ptr<auto> y;
};
的类型y
会然后由我cpp
文件来确定。
这不是相当了同样的问题Can't use std::unique_ptr<T> with T being a forward declaration因为这个问题的答案是使用前向声明。这个问题是关于使用前向声明时的一个问题。
只是前面声明的结构?或者你正在努力避免做什么? – Borgleader
[不能使用std :: unique \ _ptr而T是前向声明](http://stackoverflow.com/questions/28386185/cant-use-stdunique-ptrt-with-t-being- a-forward-declaration) –
LogicStuff
@LogicStuff不完全;请参阅编辑。 – sdgfsdh