overloading

Does C# 4.0 and a combination of optional parameters and overloads give you a warning about ambiguity?

做~自己de王妃 提交于 2019-12-08 19:38:07
问题 I've started reading Jon Skeet's early access version of his book, which contains sections on C# 4.0, and one thing struck me. Unfortunately I don't have Visual Studio 2010 available so I thought I'd just ask here instead and see if anyone knew the answer. If I have the following code, a mixture of existing code, and new code: public void SomeMethod(Int32 x, Int32 y) { ... } public void SomeMethod(Int32 x, Int32 y, Int32 z = 0) { ... } Will the compiler complain either at the definition site

C++ - Constructor overloading - private and public

佐手、 提交于 2019-12-08 16:42:16
问题 Can you tell me why the following code is giving me the following error - call of overloaded "C(int)" is ambiguous I would think that since C(char x) is private, only the C(float) ctor is visible from outside and that should be called by converting int to float. But that's not the case. class C { C(char x) { } public: C(float t) { } }; int main() { C p(0); } 回答1: This is discussed in "Effective C++" by Scott Meyer. The reason this is ambiguous is that they wanted to ensure that merely

Grandparent overloaded function in child [duplicate]

拥有回忆 提交于 2019-12-08 16:23:52
问题 This question already has answers here : Function with same name but different signature in derived class (2 answers) Closed 2 years ago . I need to understand why C++ don't allow to access Grandparent overloaded functions in Child if any of the overloaded function is declared in Parent. Consider the following example: class grandparent{ public: void foo(); void foo(int); void test(); }; class parent : public grandparent{ public: void foo(); }; class child : public parent{ public: child(){ /

Define two methods with same parameter type

佐手、 提交于 2019-12-08 15:34:49
问题 Today I ran into a scenario where I have to create a method that share the same name, params count and params types with existent one, Something like this: public static Department GetDepartment(string departmentName) { //LOGIC } public static Department GetDepartment(string employeeID) { //LOGIC } at first glance I just said why not to name it with a different name and get things done, but I couldn't! I do want to maintain the readability of my code i'm working on, I want it to be overloaded

Confusion in method overloading using abstract class in java

情到浓时终转凉″ 提交于 2019-12-08 14:23:44
问题 abstract class Cell<Q> { public abstract Q getValue(); // abstract method } class Cell1 extends Cell<Integer> { public Integer getValue() {// abstract method implementation return 0; } } class Cell2 extends Cell<String> { public String getValue() { // abstract method implementation return "razeel"; } } class test { public static void main(String[] a) { Cell obj=new Cell1(); int ab=(Integer) obj.getValue(); Cell objs=new Cell2(); String str=objs.getValue().toString(); System.out.println("ab===

function overloading in swift [duplicate]

给你一囗甜甜゛ 提交于 2019-12-08 12:57:45
问题 This question already has answers here : Compiler error: Method with Objective-C selector conflicts with previous declaration with the same Objective-C selector (6 answers) Closed 4 years ago . I am trying to create two methods with the following arguments but the compiler is complaining that they are ambiguous. I am following a youtube series to learn Swift and it seems to be fine in the video there. What am I missing? func performOperation(operation: Double -> Double){ func performOperation

Visual C# - Associate event handler with CellDoubleClick event

隐身守侯 提交于 2019-12-08 08:09:48
问题 I'm working in visual studio and trying to get information from a DataGridView cell when the user double clicks on it. I basically set up the CellDoubleClick event just like any other Click event but that doesn't seem to work. Code: Form1.cs private void dataGridView1_CellDoubleClick(Object sender, DataGridViewCellEventArgs e) { System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder(); messageBoxCS.AppendFormat("{0} = {1}", "ColumnIndex", e.ColumnIndex); messageBoxCS

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

懵懂的女人 提交于 2019-12-08 07:53:36
问题 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

Exporting overloaded functions with fpc

吃可爱长大的小学妹 提交于 2019-12-08 07:35:26
问题 I need to create a dll within fpc (delphi-mode). It works fine - but for some reasons, I want to do something (in a unit) like function doSomeThing(a:type1):type2;stdcall; function doSomeThing(a:type3):type4;stdcall; and in the library (for building the dll using the unit above) exports doSomeThing(a:type1) name 'doSomeThingTYPE1', doSomeThing(a:type3) name 'doSomeThingTYPE3'; The syntax is self explanatory and is told in How to export Overload functions from DLL? . But it seems to be

“Overload” function template based on function object operator() signature

≯℡__Kan透↙ 提交于 2019-12-08 07:14:46
问题 Consider this example of a function template that takes a function reference as its first argument. It is overloaded based on the function signature of that first argument. The body of each overload feeds the 1st argument function appropriately for it's signature. template<typename T> struct MapTtoT { typedef T (type)(const T); }; template<typename T> std::vector<T> map_vec( const typename MapTtoT<T>::type& fnc, const std::vector<T>& source) { std::vector<T> dest; dest.reserve(source.size());