ambiguous

Ambiguous method from inheritance when using a CRTP pattern

試著忘記壹切 提交于 2020-01-23 12:18:26
问题 I am defining a DoubleWrapper class inheriting from two CRTP base classes, Ratioable and Divable , that both define operator/() , with different signatures: T operator/(double const& scalar) const { return T(this->underlying().get() / scalar); } double operator/(T const& other) const { return this->underlying().get() / other.get(); } They differ both by return type and parameter type. However compiler is complaining about operator/() being ambiguous. Note that the constructor is explicit so

Ambiguous method from inheritance when using a CRTP pattern

我怕爱的太早我们不能终老 提交于 2020-01-23 12:18:18
问题 I am defining a DoubleWrapper class inheriting from two CRTP base classes, Ratioable and Divable , that both define operator/() , with different signatures: T operator/(double const& scalar) const { return T(this->underlying().get() / scalar); } double operator/(T const& other) const { return this->underlying().get() / other.get(); } They differ both by return type and parameter type. However compiler is complaining about operator/() being ambiguous. Note that the constructor is explicit so

ambiguous operator[] in variadic template

十年热恋 提交于 2020-01-23 07:41:46
问题 I'm trying to compile this example, where a variadic class template inherits from a variadic amount of bases, each of which implements a different operator[] : #include <iostream> template <typename T> struct Field { typename T::value_type storage; typename T::value_type &operator[](const T &c) { return storage; } }; template<typename... Fields> struct ctmap : public Field<Fields>... { }; int main() { struct age { typedef int value_type; }; struct last_name { typedef std::string value_type; }

Why can't GCC disambiguate multiple inherited functions (yet clang can)? [duplicate]

感情迁移 提交于 2020-01-22 13:43:25
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Why do multiple-inherited functions with same name but different signatures not get treated as overloaded functions? This fails to compile in the indicated place with g++ 4.6.1: enum Ea { Ea0 }; enum Eb { Eb0 }; struct Sa { void operator()(Ea) {} }; struct Sb { void operator()(Eb) {} }; struct Sbroken : Sa, Sb {}; struct Sworks { void operator()(Ea) {} void operator()(Eb) {} }; int main() { Sworks()(Ea0);

Why can't GCC disambiguate multiple inherited functions (yet clang can)? [duplicate]

我的梦境 提交于 2020-01-22 13:42:32
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Why do multiple-inherited functions with same name but different signatures not get treated as overloaded functions? This fails to compile in the indicated place with g++ 4.6.1: enum Ea { Ea0 }; enum Eb { Eb0 }; struct Sa { void operator()(Ea) {} }; struct Sb { void operator()(Eb) {} }; struct Sbroken : Sa, Sb {}; struct Sworks { void operator()(Ea) {} void operator()(Eb) {} }; int main() { Sworks()(Ea0);

Avoiding implicit def ambiguity in Scala

不想你离开。 提交于 2020-01-11 04:30:09
问题 I am trying to create an implicit conversion from any type (say, Int) to a String... An implicit conversion to String means RichString methods (like reverse) are not available. implicit def intToString(i: Int) = String.valueOf(i) 100.toCharArray // => Array[Char] = Array(1, 0, 0) 100.reverse // => error: value reverse is not a member of Int 100.length // => 3 An implicit conversion to RichString means String methods (like toCharArray) are not available implicit def intToRichString(i: Int) =

Ambiguous type using parameterized types Haskell

谁说我不能喝 提交于 2020-01-07 02:04:29
问题 I have a pretty straightforward function that takes a parameterized data type and returns the same type: {-# LANGUAGE ScopedTypeVariables #-} class IntegerAsType a where value :: a -> Integer newtype (Num a, IntegerAsType n) => PolyRing a n = PolyRing [a] deriving (Eq) normalize :: (Num a, IntegerAsType n) => (PolyRing a n) -> (PolyRing a n) normalize r@(PolyRing xs) | (genericLength xs) == len = r | ... [other cases] where len = (value (undefined :: n)) The idea is that normalize will take a

Ambiguous type using parameterized types Haskell

别等时光非礼了梦想. 提交于 2020-01-07 02:04:23
问题 I have a pretty straightforward function that takes a parameterized data type and returns the same type: {-# LANGUAGE ScopedTypeVariables #-} class IntegerAsType a where value :: a -> Integer newtype (Num a, IntegerAsType n) => PolyRing a n = PolyRing [a] deriving (Eq) normalize :: (Num a, IntegerAsType n) => (PolyRing a n) -> (PolyRing a n) normalize r@(PolyRing xs) | (genericLength xs) == len = r | ... [other cases] where len = (value (undefined :: n)) The idea is that normalize will take a

Avoiding ambiguity in overload resolution

青春壹個敷衍的年華 提交于 2020-01-06 09:06:50
问题 This is a follow up to this question so if you need to see the Register class please refer to that question. Now based on the supplied answer I have written a function to do just that. I have 2 versions of the function one that will store the results back into the original and one that will return a copy. Here are my functions: template<std::uint64_t N> void reverseBitOrder( Register<N>& reg ) { auto str = reg.register_.to_string(); std::reverse(str.begin(), str.end()); auto x = vpc::Byte(str

Avoiding ambiguity in overload resolution

怎甘沉沦 提交于 2020-01-06 09:06:31
问题 This is a follow up to this question so if you need to see the Register class please refer to that question. Now based on the supplied answer I have written a function to do just that. I have 2 versions of the function one that will store the results back into the original and one that will return a copy. Here are my functions: template<std::uint64_t N> void reverseBitOrder( Register<N>& reg ) { auto str = reg.register_.to_string(); std::reverse(str.begin(), str.end()); auto x = vpc::Byte(str