overloading

How to operate different class just one functionsone

class A {}; class B {}; class C {}; class D {}; //A+B , A+C, B+C , A+D, D+C namely all of these combinations will be possible just one functions ...

C++ template overloading - wrong function called

template<typename T> T* Push(T* ptr); template<typename T> T* Push(T& ref); template<typename T, typename T1> T* Push(T1&& ref); I have int i = 0; Push<int>(i); But the compiler calls it ambiguous. How is that ambiguous? The second function is clearly the preferred match since it's more specia...

Default values on arguments in C functions and function overloading in C

Converting a C++ lib to ANSI C and it seems like though ANSI C doesn't support default values for function variables or am I mistaken? What I want is something like int funcName(int foo, bar* = NULL); Also, is function overloading possible in ANSI C? Would need const char* foo_property(foo_t* /* this */, int /* property_number*/); ...

Constructor Overload Problem in C++ Inheritance

Here my code snippet: class Request { public: Request(void); ……….. } Request::Request(void) { qDebug()<<"Request: "<<"Hello World"; } class LoginRequest :public Request { public: LoginRequest(void); LoginRequest(QDomDocument); …………… } LoginRequest::LoginRequest(void) { qDebug()<<"LoginRequest: "<<"Hello World"; requestType=LOG...

Know if a MySQL server is overloaded with PHP

Hi, It's possible to know if a MySQL server is overloaded (with PHP), and if it's overloaded show a static page (something like Twitter's fail whale)? How can I do it? Thanks! ...

Overloading + to add two pointers

I have a String class and I want to overload + to add two String* pointers. something like this doesn't work: String* operator+(String* s1, String* s2); Is there any way to avoid passing by reference. Consider this example: String* s1 = new String("Hello"); String* s2 = new String("World"); String* s3 = s1 + s2; I need this kind o...

How to use an overloaded function as an argument of function template?

Hello, I think everyone has experience working with a code like the following: void fun(Type1&); void fun(Type2&); vector<Type1> vec; for_each(vec.begin(), vec.end(), fun); Of course that won't compile, because it's not clear which function to be passed. And what's your commonly-used solution to the problem? I know this will w...

Can overloading is possible with two version of function, constant member function and function without const

Hello, I just came across various overloading methods like type of parameter passed, varying number of parameters, return type etc. I just want to know that can I overload a function with following two version //function which can modify member String //constant member function String Please let me know the reason behind it. Than...

Overload Resolution and Optional Arguments in C# 4

I am working with some code that has seven overloads of a function TraceWrite: void TraceWrite(string Application, LogLevelENUM LogLevel, string Message, string Data = ""); void TraceWrite(string Application, LogLevelENUM LogLevel, string Message, bool LogToFileOnly, string Data = ""); void TraceWrite(string Application, LogLevelENUM L...

C++ Tracking primitive type value change

i have a complex program with weird bug that some int value is down to zero unexpectedly. so i want tracking this built-in type value, then i could debug easily. to do that, i made following ValueWatcher template class so i could track almost changes of value except when ValueWatcher is dereferencing. (i made these dereferencing operat...

Unexpected array contents in class using __get, __set and __unset

I've created a short demonstration of the problem I'm having. This isn't exactly how I'm implementing it but seems to lead to the same result. <?php class mainclass { var $vardata = array(); function &__get ($var) { if ($this->vardata[$var]) return $this->vardata[$var]; if ($var == 'foo') return $this->_loadFo...

Why is one class valid while the other is not?

As you can see, having a non void return type is important. class TestValid { public String f(List<String> list) { return null; } public Integer f(List<Integer> list) { return null; } public void test() { f(Arrays.asList("asdf")); f(Arrays.asList(123)); } } class TestInvalid { public void f(List<String> list) { ...

C++ implicit conversions and ambiguity in overloaded function call

I am facing the following problem: I have a class V (say a vector) from which I can produce two classes: CI and I (think of const_iterator and iterator). If I have a const V then I can only produce CI (again think of iterator and const_iterator). Essentially I would like to subsitute (const V& v) with (CI ci) and (V& v) with (I i). Mor...

More or less equal overloads

The following code compiles in C# 4.0: void Foo(params string[] parameters) { } void Foo(string firstParameter, params string[] parameters) { } How does the compiler know which overload you're calling? And if it can't, why does the code still compile? ...

'No matching function' -error when trying to insert to a set (c++)

I have the following code: class asd { public: int b; asd() { b = rand() % 10; } bool operator<(asd &other) { return b < other.b; } }; int main() { asd * c; c = new asd(); set <asd> uaua; uaua.insert(c); } Yet when running it, I get this error: main.cpp|36|error: no matching function for...

When is a return type required for methods in Scala?

The Scala compiler can often infer return types for methods, but there are some circumstances where it's required to specify the return type. Recursive methods, for example, require a return type to be specified. I notice that sometimes I get the error message "overloaded method (methodname) requires return type", but it's not a general...

Overloaded constructor error

I have the following class: class Step(kind:TipoStep.Value, message:String = "", study:List[Formula] = List(), lastAdd:Set[Formula] = Set(), lastDel:Set[Formula] = Set(), add:List[Formula] = List(), del:List[Formula] = List() ) { def this(step:Step, ...

overloaded functions are hidden in derived class

In a derived class If I redefine/overload a function name from a Base class, then those overloaded functions are not accessable/visible to derived class. Why is this?? If we don't overload the oveloaded function from the base class in derived class then all the overloaded versions of that function are available to derived class objec...

boost::function and plain function pointers: ambigous overload

Given the following member function overload to take various functors class Foo { public: void bar(boost::function<void(int)> func); void bar(boost::function<void(float)> func); void bar(boost::function<void(const std::vector<float>&)> func); } and the function void baz(float f) { std::cout << "float :" << f << st...

PHP overloading a function from a parent class

Hi all, I have a thing which I thought should work, but it doesn't. I have several Controller_## classes, they all extend from Controller_Core. Each Controller_##-class has a public function Save(). Now I figured that I want to perform some other general checking (addslashes for each $_POST-var) and thought if I add a public function S...