[英]Injecting parameters with dependency injection
我試圖在我的項目中設置依賴注入( https://boost-ext.github.io/di/ )並得到以下編譯錯誤“沒有匹配的重載 ZC1C425268E683id941AB507A 模板”和“inval74F”1 .
我的測試設置如下
#include "di.hpp"
namespace di = boost::di;
class IA{
public:
virtual void doSomething() = 0;
};
class IB{
public:
virtual void doSomething() = 0;
};
class IC{
public:
virtual void doSomething() = 0;
};
class A : public IA {
public:
void doSomething() override {
}
};
class B : public IB {
public:
void doSomething() override {
}
};
class C : public IC{
std::shared_ptr<A> a_;
std::shared_ptr<B> b_;
public:
C(std::shared_ptr<A> a, std::shared_ptr<B> b) : a_(a), b_(b){}
void doSomething() override {
}
};
int main(int argc, char *argv[]) {
const auto injector = di::make_injector(
di::bind<IA>.to<A>(),
di::bind<IB>.to<B>(),
di::bind<IC>.to<C>()
);
auto test = injector.create<IC>();
}
以下是我的詳細編譯錯誤:
錯誤 C2672: 'boost::ext::di::v1_2_0::core::injector<TConfig,boost::ext::di::v1_2_0::core::poolboost::ext::di::v1_2_0:: aux::type_list<>,boost::ext::di::v1_2_0::core::dependency<TScope,TExpected,T,TName,TPriority,TCtor>,boost::ext::di::v1_2_0::core ::dependency<TScope,IB,B,TName,TPriority,TCtor>,boost::ext::di::v1_2_0::core::dependency<TScope,IC,C,TName,TPriority,TCtor>>::create ': 沒有找到匹配的重載 function 與 [ TConfig=boost::ext::di::v1_2_0::config, TScope=boost::ext::di::v1_2_0::scopes::deduce, TExpected=IA, T= A、TName=boost::ext::di::v1_2_0::no_name, TPriority=void, TCtor=boost::ext::di::v1_2_0::core::none]
錯誤 C2770:'T boost::ext::di::v1_2_0::core::injector<TConfig,boost::ext::di::v1_2_0::core::poolboost:: 的顯式模板參數無效ext::di::v1_2_0::aux::type_list<>,boost::ext::di::v1_2_0::core::dependency<TScope,TExpected,T,TName,TPriority,TCtor>,boost::ext ::di::v1_2_0::core::dependency<TScope,IB,B,TName,TPriority,TCtor>,boost::ext::di::v1_2_0::core::dependency<TScope,IC,C,TName ,TPriority,TCtor>>::create(void) const' 與 [ TConfig=boost::ext::di::v1_2_0::config, TScope=boost::ext::di::v1_2_0::scopes::deduce , TExpected=IA, T=A, TName=boost::ext::di::v1_2_0::no_name, TPriority=void, TCtor=boost::ext::di::v1_2_0::core::none ]
注意:見 'boost::ext::di::v1_2_0::core::injector<TConfig,boost::ext::di::v1_2_0::core::poolboost::ext::di::v1_2_0 的聲明::aux::type_list<>,boost::ext::di::v1_2_0::core::dependency<TScope,TExpected,T,TName,TPriority,TCtor>,boost::ext::di::v1_2_0: :core::dependency<TScope,IB,B,TName,TPriority,TCtor>,boost::ext::di::v1_2_0::core::dependency<TScope,IC,C,TName,TPriority,TCtor>>: :create' with [ TConfig=boost::ext::di::v1_2_0::config, TScope=boost::ext::di::v1_2_0::scopes::deduce, TExpected=IA, T=A, TName= boost::ext::di::v1_2_0::no_name, TPriority=void, TCtor=boost::ext::di::v1_2_0::core::none]
任何想法我做錯了什么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.