overloading

wrapping template function and <unresolved overloaded function type

纵饮孤独 提交于 2019-12-07 16:40:52
问题 I have problem with my wrapping function. template <typename Iter, typename SomeFunction> void wrap(Iter first, Iter last, SomeFunction someFunction) { someFunction(first, last); } I would like to use it like this: template <typename Iter> void fill5(Iter first, Iter last) { fill(first, last, 5); } int main() { vector<int> v(100, -1); wrap(v.begin(), v.end(), fill5); } But I get test.cpp: In function ‘int main()’: test.cpp:16:40: error: no matching function for call to ‘wrap(std::vector<int>:

ambiguous reference to overloaded definition, from a Java library

╄→гoц情女王★ 提交于 2019-12-07 16:38:04
问题 I was tying to convert this example for JsonPath to Scala. It should be easy with java like: List<String> authors = JsonPath.read(json, "$.store.book[*].author"); Which I converted to this Scala: val authors = JsonPath.read(json, "$.store.book[*].author"); Where json is a String. But I get this compile error. ambiguous reference to overloaded definition, both method read in object JsonPath of type [T](x$1: String, x$2: String, x$3: <repeated...>[com.jayway.jsonpath.Filter[_]])T and method

function overload and type conversion resolution

主宰稳场 提交于 2019-12-07 16:23:35
问题 why do we not see a "undefined call to overloaded function" error with the code bellow? just because int is a built in type? where in the standard can I find the guarantee for the conversion to built in type, such as in the code bellow?... thanks! #include <iostream> using namespace std; class B { public: operator int(){ return 0; } }; class A { public: A( int i ) { }; }; void f ( int i ) { cout << "overload f(int) was used!";}; void f ( A a ) { cout << "overload f(A) was used!" ;}; int main

Swift 3 closure overload resolution

流过昼夜 提交于 2019-12-07 15:55:44
问题 I'm confused by function overload resolution with closures in Swift 3. For example, in the code: func f<T>(_ a: T) { print("Wide") } func f(_ a: (Int)->(Int)) { print("Narrow") } f({(a: Int) -> Int in return a + 1}) I expect Narrow , not Wide , to be printed to the console. Can anyone explain why the more specific overload gets chosen for non-closure arguments but not for closures or is this a compiler bug? Swift 2 exhibited the expected behavior. 回答1: This is probably due to the change in

Calling overloaded function using templates (unresolved overloaded function type compiler error) [duplicate]

断了今生、忘了曾经 提交于 2019-12-07 15:20:14
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: How to get the address of an overloaded member function? I have a function overloaded for a set of types in a class inheritence heirarchy, e.g. Share with FutureShare and OptionShare derived. virtual unsigned rank() const { return getValue(*this, rank_, &ShareUtils::getRank); } template<typename TShare , typename TMember, typename TGetMemberFunc > TValue& getValue(const TShare& share, boost::optional<TMember>&

Swift generic method should use overloaded generic function

帅比萌擦擦* 提交于 2019-12-07 14:19:05
问题 I'm having trouble getting the desired effect with Swift generics. I defined some generic functions, but for specific cases I would like to override them to provide additional features. When I call the functions from a non generic method/function everything works fine (it uses the specific versions when the argument types match and the generic version otherwise), but when I call the functions from a generic method/function it always uses the generic version of the function (never the specific

Java: How can one put to use constructor overloading in enums?

♀尐吖头ヾ 提交于 2019-12-07 12:36:57
问题 I am working with enumerations in Java. As I can see, it is possible to overload an enumeration constructor. My question is it possible at all to benefit from constructor overloading in this context given that as far as I understand it is possible neither to call it by yourself no to force the compiler to call a particular one that you would like to call? Appreciate the time your take to clarify that stuff to me and hope it would also be useful for others who might have the same question in

Overloading method in base class, with member variable as default

江枫思渺然 提交于 2019-12-07 08:53:35
问题 I have a Class structure as follows: class Base { public: void setDefault( uint8_t my_default ) { m_default = my_default; } void method( uint8_t * subject ) { method( subject, m_default ); } virtual void method( uint8_t * subject, uint8_t parameter ) =0; protected: uint8_t m_default; }; class Derived1 : public Base { public: void method ( uint8_t * subject, uint8_t parameter ) { /* do something to subject */ } }; class Derived2 : public Base { public: void method ( uint8_t * subject, uint8_t

Return type 'never' if an optional parameter is given to be a specific value

折月煮酒 提交于 2019-12-07 08:44:28
I have a function that takes an optional boolean argument that defaults to false . When the argument is false , the function returns a string . When the argument is true , the function should return type never . Here's what I tried: function example(arg: true): never; function example(arg = false): string { //... } This feels like it should work: arg is inferred to have a boolean type, and when it is not passed or passed as false , example returns string . When it is passed as true , the overload kicks in and example returns never . However, this doesn't work at all. TypeScript gives arg the

Ambiguous Reference/Value Versions of Functions

北城以北 提交于 2019-12-07 07:31:08
问题 Consider the following function prototypes: void Remove(SomeContainer& Vec, const std::size_t Index); SomeContainer Remove(SomeContainer Vec, const std::size_t Index); The second is implemented in terms of the first. That is to say, they are functionally identical in every way except that one is pass-by-reference and the other is pass-by-value. However, GCC says these are ambiguous in cases like this, even though the first form is the only one that does not return a value: Remove