I want to use unique_ptr with an incomplete type. The code below does what I expected and can't compile.
#include <memory>
struct bar;
struct foo {
foo() {
}
~foo() {
}
std::unique_ptr<bar> pb{};
};
int main() {
foo f;
}
However, if I add the definition of bar after the function main's definition. It can compile.
#include <memory>
struct bar;
struct foo {
foo() {
}
~foo() {
}
std::unique_ptr<bar> pb{};
};
int main() {
foo f;
}
struct bar {
};
I have no idea why the definition after main can help main compile. Is that behavior defined in c++ standard?