我有一些麻煩向前宣稱使用boost::enable_if
功能:下面這段代碼給了我一個編譯器錯誤:正向宣稱使用enable_if功能:曖昧通話
// Declaration
template <typename T>
void foo(T t);
// Definition
template <typename T>
typename boost::enable_if<boost::is_same<T, int> >::type foo(T t)
{
}
int main()
{
foo(12);
return 0;
}
編譯時,我得到一個「曖昧致電foo「錯誤。根據enable_if
的定義,當條件爲真時,'type'typedef對應於void
,所以據我所知,foo
的兩個簽名匹配。爲什麼編譯器認爲它們是不同的,是否有正確的方法來轉發聲明foo
(最好不要重複enable_if
部分)?
匹配的問題,編譯器不能決定你要使用的模板。 – 2010-01-08 18:26:44