overloading

php overload = operator [duplicate]

巧了我就是萌 提交于 2019-12-18 07:39:32
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Operator Overloading in PHP Is there a way to overload the = operator ? So want I is the following: class b{ function overloadis(){ // do somethng } } $a = new b(); $a = 'c'; In the example above, I want that when $a = 'c'; is called, the method overloadis is called first and then that function desides if the action (assign 'c' to $a) is executed or aborted. Is it possible to do this ? Thnx in advance, Bob 回答1:

Want to create a Generic AsyncTask

血红的双手。 提交于 2019-12-18 07:24:12
问题 In my project. For almost every Activity I have to make an AsyncTask .. And Almost the work is same for all of them. I want to create a generic AsyncTask and extends it. And i also want to send the methods in the constructor like this. Then Whenever I a class extends it . Just it have to create a method and it will do our work easily . and less coding .. It is time consuming .. Thanks for help in Advance.. One of my asyncTask is private class GetData extends AsyncTask<String, Void, JSONObject

Why class member functions shadow free functions with same name?

ε祈祈猫儿з 提交于 2019-12-18 05:50:08
问题 It recently came to my attention that member functions completely shadow free functions with the same name when inside the class. And by completely I mean that every free function with the same name is not considered for overload resolution at all. I can understand why it's done with something like this: void f(); struct S { void f(); void g() { f(); // calls S::f instead of ::f } }; where the functions have identical signatures, its only natural as variable scoping works the same way. But

Overloading base method in derived class

∥☆過路亽.° 提交于 2019-12-18 03:22:29
问题 So I was playing with C# to see if it matched C++ behavior from this post: http://herbsutter.com/2013/05/22/gotw-5-solution-overriding-virtual-functions/ when I came across this very strange behavior: public class BaseClass { public virtual void Foo(int i) { Console.WriteLine("Called Foo(int): " + i); } public void Foo(string i) { Console.WriteLine("Called Foo(string): " + i); } } public class DerivedClass : BaseClass { public void Foo(double i) { Console.WriteLine("Called Foo(double): " + i)

Overloading on std::function<…>

此生再无相见时 提交于 2019-12-18 03:19:49
问题 Given the following code :- #include <algorithm> #include <iostream> #include <functional> #include <string> void func(std::function<void(void)> param) { param(); } void func(std::function<void(int)> param) { param(5); } int main(int argc, char* argv[]) { func([] () { std::cout << "void(void)" << std::endl; }); func([] (int i) { std::cout << "void(int): " << i << std::endl; }); std::string line; std::getline(std::cin, line); return 0; } Compile error from VS2010 :- CppTest.cpp(18): error

Method overloading with primitives and their wrappers

你离开我真会死。 提交于 2019-12-18 03:14:20
问题 I am trying to formulate the rules that are being used in the scenarios below. Please explain why I am getting 2 different outputs. Scenario 1 output: I am an object. class Test { public static void main (String[] args) { Test t = new Test(); byte b_var = 10; t.do_the_test(b_var); } public void do_the_test(Character c) { System.out.println("I am a character."); } public void do_the_test(Integer i) { System.out.println("I am an integer."); } public void do_the_test(Object obj) { System.out

Why can't decltype work with overloaded functions?

北慕城南 提交于 2019-12-18 02:46:38
问题 decltype fails if the function you're calling it on is overloaded, as in this code: #include <iostream> int test(double x, double y); double test(int x, int y); char test(char x, int y); int main() { std::cout << decltype(test) << std::endl; return 0; } Results: error: decltype cannot resolve address of overloaded function I understand that this is because decltype can't figure out which function you're trying to get the type of. But why isn't there another way to make this work, like this:

Why is this method overloading ambiguous?

≡放荡痞女 提交于 2019-12-17 23:16:31
问题 public class Primitive { void m(Number b, Number ... a) {} // widening, autoboxing->widening->varargs void m(byte b, Number ... a) {} // unboxing, autoboxing->widening->varargs public static void main(String[] args) { Byte b = 12; Primitive obj = new Primitive(); obj.m(b, 23); } } I have already searched and found that widening priority is higher than unboxing, so in above method invocation, first method should have been called because second parameter is same for both. But this does not

Is it possible to get c# to use method overload of most specific type rather than base type?

爷,独闯天下 提交于 2019-12-17 21:06:42
问题 If you have a method which is overloaded with a derived type, the method called at run-time depends on the type of your variable, even if the underlying object is actually of the derived type: class Program { static void Main(string[] args) { BaseClass theBaseObject = new BaseClass { Foo = "FOO" }; DerivedClass theDerivedObject = new DerivedClass { Foo = "FOO", Bar = "BAR" }; Processor processor = new Processor(); Console.WriteLine(processor.Compose(theBaseObject)); Console.WriteLine

How do I overload the operator * when my object is on the right side in C++?

穿精又带淫゛_ 提交于 2019-12-17 21:05:43
问题 I want to implement "operator * " overloading INSIDE my class, so I would be able to do the following: Rational a(1, 2), b; b = 0.5 * a; // b = 1/4 Notice that b is on the right side, is there a way to do such a thing inside "Rational" class? 回答1: No. You must define operator* as a free function. Of course, you could implement it in terms of a member function on the second argument. 回答2: Yes: class Rational { // ... friend Rational operator*(float lhs, Rational rhs) { rhs *= lhs; return rhs;