2
我有一個容器template <typename T> class A
其中operator+
需要重載許多其他容器,表達式模板和文字類型U
。模板化的重載運算符不明確
我目前的策略是定義一個模板函數wrap
封裝元素如何獨立進行訪問,並定義
template <typename T, typename U>
auto operator+(Wrapped<T>&& lhs, Wrapped<U>&& rhs) -> decltype(...)
{
....
}
以下重載operator+
,然而,是模糊的:
template <typename T, typename U>
auto operator+(const A<T>& lhs, U&& rhs) ->
decltype(wrap(lhs) + wrap(std::forward<U>(rhs)))
{
return wrap(lhs) + wrap(std::forward<U>(rhs));
}
template <typename T, typename U>
auto operator+(T&& lhs, const A<U>& rhs) ->
decltype(wrap(std::forward<T>(lhs)) + wrap(rhs))
{
return wrap(std::forward<T>(lhs)) + wrap(rhs);
}
我怎樣才能解決最好的歧義?
。不過,我仍然會遇到過度的歧義。 – jk4736
@ jk4736如果你發佈更多的代碼,它可能會告訴如何解決歧義。這個呼籲有什麼爭議含糊不清? – ecatmur
哦!它可能是模棱兩可的,因爲operator +被稱爲右值A?很可能是 –
jk4736