Closed victl closed 4 years ago
I've figured out that when your class have unique_ptr
, then a direct instance can't be created by boost-di
, because the copy constructor is implicitly deleted. I suppose the create<A>()
method is triggering a copy action somewhere inside.
Everything making sense to me, except the fact that if you comment out the destructor it compiles.
For a workaround, I can create<std::unique_ptr<A>>()
instead.
Thanks, @victl. You are right, in that case defining the destructor requires the move.
You can do it by using rvalue ref or creating std::unique_ptr to avoid deleted copies.
int main() {
[[maybe_unused]] auto&& a = di::make_injector().create<A&&>();
}
Full example here -> https://wandbox.org/permlink/V7Ap9C4YtfkFAGva
@krzysztof-jusiak I have tried this method in my actual project with more complicated codes, I can't create rvalue
references or unique_ptr
either. Same problem: can't have destructor, compiles well without it.
Can you explain why the destructor matters here?
Hi. Check this out. I remember I have already answered this question. https://github.com/boost-experimental/di/issues/428
Expected Behavior
The following code should compile:
Actual Behavior
Won't compile. However, if you comment out the destructor
~A(){}
, then it compiles correctly.Am I using
std::unique_ptr
incorrectly?Complete error output from
MSVC
can be found HERESpecifications
8e02462
MSVC 14.24.28314
, andg++ 5.4.0