我試圖使用多個模板將數據傳遞到一個函數,但只使用第一個模板參數作爲過濾器。事情是這樣的:未指定的模板參數
template <typename A, typename B>
class Component {
};
template <typename A>
class Context {
public:
void add(Component<A, void *> comp) {
}
}
typedef struct Foo { int x; } Foo;
typedef struct Bar { int y; } Bar;
Context<Foo> *context = new Context<Foo>();
Component<Foo, Bar> *comp = new Component<Foo, Bar>();
context->add(comp); // error
但是,編譯器抱怨說,它不能轉換Component<Foo, Bar>
到Component<Foo, void *>
。有沒有辦法做到這一點?