爲什麼X中的方法測試模糊不清,以及如何解決這個問題?在函數重載中使用標籤
struct A{};
struct B{};
template<typename T>
struct I { void test(T){} };
struct X : public I<A>, I<B> {};
int main(int argc, const char *argv[])
{
X x;
x.test(A());
return 0;
}
編譯錯誤:
In function ‘int main(int, const char**)’:
error: request for member ‘test’ is ambiguous
error: candidates are: void I<T>::test(T) [with T = B]
error: void I<T>::test(T) [with T = A]
您是否暗示當前代碼含糊不清,並且無法編譯,即此代碼修復了歧義,但您不喜歡該樣式,什麼? – Useless 2012-01-05 12:48:44
@無用,我已經詳細闡述了這個問題,澄清一下 – Allan 2012-01-05 12:57:53