function-overloading

Overloading C++ STL methods

How can I overload the STL implementation for methods like find, erase and insert to take varying parameters? I tried to look up the overloading of STL methods but couldn't find any help. ...

Is there a reason that C99 doesn't support function overloading?

Apparently (at least according to gcc -std=c99) C99 doesn't support function overloading. The reason for not supporting some new feature in C is usually backward compatibility, but in this case I can't think of a single case in which function overloading would break backward compatibility. What is the reasoning behind not including thi...

How do I call the original function from the overloaded function in a category?

In Objective-C, I have a category for a class: @interface UILabel(CustomInit) - (id)initWithCoder:(NSCoder *)coder; @end What I'm doing is writing a custom init function that does some extra stuff, and what I'd like to do, is in this custom init function, call the UILabel's base initWithCoder. Is this possible? How so? EDIT Thanks...

C++ Function Overloading Similar Conversions

I'm getting an error which says that two overloads have similar conversions. I tried too many things but none helped. Here is that piece of code CString GetInput(int numberOfInput, BOOL clearBuffer = FALSE, UINT timeout = INPUT_TIMEOUT); CString GetInput(int numberOfInput, string szTerminationPattern, BOOL clearBuffer = FALSE, UINT tim...

VBA excel Overload another add-in function

Question! I have an add-in we created at work, say foo.xla, and it has a function foo_sub(arg1). Now, I want to improve the way that foo_sub(arg1) behaves but withour editting the original add-in code, since as soon as they update it, I must migrate my code from the old add-in to the newer. Is there a way I could write foo_sub(arg1) i...

In C++ how is function overloading typically implemented?

If there is no function overloading, the function name serves as the address of the function code, and when a function is being called, its address is easy to find using its name. However with function overloading, how exactly can the program find the correct function address? Is there a hidden table similar to virtual tables that stores...

How to force template function overload for boost::bind?

Hi, I'm trying to create predicate for std::find_if by using boost::bind together with boost::contains (from boost/algoritm/string library). Following snippet shows two ways how I'm trying to accomplish this. #include <boost/algorithm/string.hpp> #include <boost/bind.hpp> #include <boost/function.hpp> #include <iostream> #include <s...

c++ function overload resolution regarding templated type and class hierarchy

A templated function gives me the convenience to operate on a variety of types: template<typename T> void destroy(T* obj) { delete obj; } But at some point I want to do some specialization on a class hierarchy: class Base { virtual void doSomething(); }; class Derived : public Base {}; void destroy(Base* obj) { obj->doSomethi...

How to provide stl like container with public const iterator and private non-const iterator?

Hello, I have a class that includes a std::list and wish to provide public begin() and end() for const_iterator and private begin() and end() for just plain iterator. However, the compiler is seeing the private version and complaining that it is private instead of using the public const version. I understand that C++ will not overload...

Function overloading in C

Today, looking at the man page for open(), I've noticed this function is 'overloaded': int open(const char *pathname, int flags); int open(const char *pathname, int flags, mode_t mode); I didn't thought it's possible on C. What's the 'trick' for achieving this ? LATER EDIT: So it's not really overloading, because when using va...

Why isn't the compiler smarter in this const function overloading problem?

The following code does not compile: #include <iostream> class Foo { std::string s; public: const std::string& GetString() const { return s; } std::string* GetString() { return &s; } }; int main(int argc, char** argv){ Foo foo; const std::string& s = foo.GetString(); // error return 0; } I get the following error: const...

Strange overloading rules in C++

I'm trying to compile this code with GCC 4.5.0: #include <algorithm> #include <vector> template <typename T> void sort(T, T) {} int main() { std::vector<int> v; sort(v.begin(), v.end()); } But it doesn't seem to work: $ g++ -c nm.cpp nm.cpp: In function ‘int main()’: nm.cpp:9:28: error: call of overloaded ‘sort(std::vector<...

c++ function overloading, making fwrite/fread act like PHP versions

I'm used to the PHP fwrite/fread parameter orders, and i want to make them the same in C++ too. I want it to work with char and string types, and also any data type i put in it (only if length is defined). I am total noob on c++, this is what i made so far: Edit: fixed the std::string &buf size_t fwrite(FILE *fp, const std::string &bu...

Static Variables in Overloaded Functions

I have a function which does the following: When the function is called and passed a true bool value, it sets a static bool value to true When the function is called and passed a string, if the static bool value is set to true, it will do something with that string Here is my concern -- will a static variable remain the same between ...

Explanation of ambiguity in function overloading for this example in C++.

I'm reading Stroustrup's book, the section on overloading and related ambiguities. There's an example as follows: void f1(char); void f1(long); void k(int i) { f1(i); //ambiguous: f1(char) or f1(long) } As the comment states, the call is ambiguous. Why? The previous section in the book stated 5 rules based on matching formal...

How to override functions from String class in C#.

For example, I need to see if a string contains a substring, so I just do: String helloworld = "Hello World"; if(helloworld.Contains("ello"){ //do something } but if I have an array of items String helloworld = "Hello World"; String items = { "He", "el", "lo" }; I needed to create a function inside the String class that would r...

Function overloading and inheritance

Possible Duplicate: Why does an overridden function in the derived class hide other overloads of the base class? I recently came across this interesting inheritance example - class FirstClass { public: void MethodA (int) { cout << "ONE\n";} void MethodA (int, int) { cout << "TWO\n";} }; class SecondClass : pu...

Adding new functions to an interface

Hi, I need to create overloads for functions on an existing interface without affecting any components that currently implement or make use of the interface (ideally). I figure I have a couple of options: Simplified Original interface: public interface IServerComponent { bool Add(int a, int b); } I can add the new overloaded fu...

Possible compilation errors in C++

In C++, what kind of compilation errors might I run into while using function overloading, and when might these occur? ...

Method overloading standard protocol?

If you add a third signature for a method, do you make the second and third variations directly call the first (the implemented variation), or do you make the third call the second and the second call the first. It would seem to me that the extra method call would be overhead you could live without, so you'd want all the methods to call...