overloading

SqlParameter constructor compiler overload choice

别来无恙 提交于 2020-01-25 00:31:27
问题 When creating an SqlParameter (.NET3.5) or OdbcParameter , I often use the SqlParameter(string parameterName, Object value) constructor overload to set the value in one statement. However, when I tried passing a literal 0 as the value parameter, I was initially caught by the C# compiler choosing the (string, OdbcType) overload instead of (string, Object) . MSDN actually warns about this gotcha in the remarks section, but the explanation confuses me. Why does the C# compiler decide that a

Typescript: Return type of function based on input value (enum)

你。 提交于 2020-01-24 07:56:46
问题 I'm storing some settings into local storage and I would like to type the responses when I get (and ideally also insert) values from/to the storage. From what I've seen, the best way seems to be to use function overloading. So this is what I have now and it works: export enum SettingsKey { hasOnboarded = 'hasOnboarded', phoneNumber = 'phoneNumber' } export async function getSetting(storage: Storage, key: SettingsKey.phoneNumber): Promise<string> export async function getSetting(storage:

Typescript: Return type of function based on input value (enum)

霸气de小男生 提交于 2020-01-24 07:55:37
问题 I'm storing some settings into local storage and I would like to type the responses when I get (and ideally also insert) values from/to the storage. From what I've seen, the best way seems to be to use function overloading. So this is what I have now and it works: export enum SettingsKey { hasOnboarded = 'hasOnboarded', phoneNumber = 'phoneNumber' } export async function getSetting(storage: Storage, key: SettingsKey.phoneNumber): Promise<string> export async function getSetting(storage:

Call a functor with a specific function from an overload set

喜欢而已 提交于 2020-01-23 09:10:40
问题 Context In mathematics-related context, I'd like to define functors working on <cmath> functions. For the purpose of this question, we will be using std::invoke as our functor. This is ill-formed (live demo): std::invoke(std::sin, 0.0); (g++-8.1) error: no matching function for call to 'invoke(<unresolved overloaded function type>, double)' Indeed, std::sin is an overload set and the compiler lacks the type information to choose one of those functions. Question How could I name a specific

Call a functor with a specific function from an overload set

﹥>﹥吖頭↗ 提交于 2020-01-23 09:09:07
问题 Context In mathematics-related context, I'd like to define functors working on <cmath> functions. For the purpose of this question, we will be using std::invoke as our functor. This is ill-formed (live demo): std::invoke(std::sin, 0.0); (g++-8.1) error: no matching function for call to 'invoke(<unresolved overloaded function type>, double)' Indeed, std::sin is an overload set and the compiler lacks the type information to choose one of those functions. Question How could I name a specific

How to change this design to avoid a downcast?

我们两清 提交于 2020-01-23 02:05:08
问题 Let's say I have a collection of objects that all inherit from a base class. Something like... abstract public class Animal { } public class Dog :Animal { } class Monkey : Animal { } Now, we need to feed these animals, but they are not allowed to know how to feed themselves. If they could, the answer would be straightforward: foreach( Animal a in myAnimals ) { a.feed(); } However, they can't know how to feed themselves, so we want to do something like this: class Program { static void Main

Typescript overload arrow functions

给你一囗甜甜゛ 提交于 2020-01-22 13:48:05
问题 So we can do: export function myMethod (param: number) :number export function myMethod (param: string) :string export function myMethod (param: string | number): string | number { if (typeof param === 'string') { return param.toUpperCase() } else { return param + 1 } } Can I declare and implement it with arrow function? export var myMethodArror = (param: string): string export var myMethodArror = (param: number): number export var myMethodArror = (param: string | number): string | number =>

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);

How does the particular C function work?

时光怂恿深爱的人放手 提交于 2020-01-22 06:46:09
问题 I am trying to learn C and am very confused already. In the OOP languages i have used there exists the ability to perform method overloading, where the same function could have different parameter types and call whichever was the most appropriate. Now in C i know that this is not the case so i cant figure out the following problem, How printf() works. For example: char chVar = 'A'; int intVar = 123; float flVar = 99.999; printf("%c - %i - %f \n",chVar, intVar, flVar); printf("%i - %f - %c \n"