function

Tool to visualize Function Hierarchy trees?

Any code-analysis or "reverse-engineering" tool that can do either of these?: Calculate which classes are sub-classes of which classes Calculate which classes instantiate which classes -- (like VS Class Designer) Calculate which functions call which functions -- (much like a Call Stack) ...

Diamond inheritance and pure virtual functions

Imagine a standard diamond inheritance. Class A defines pure virtual function fx, class B defines implementation for fx, classes C and D do nothing with fx. When trying to call fx on instance of class D you'll get 'ambiguous function call' error although there is only one implementation of fx. This can be solved by B and C inheriting fro...

Friend template functions (in non-template classes), C++

If I have a non-template (i.e. "normal") class and wish to have a template friend function, how do I write it without causing a compiler error? Here is an example to illustrate what I am trying to do: template <class T> void bar(T* ptr); class MyClass // note that this isn't a template class { private: void foo(); template <...

How to best pass optional function arguments that are nearly always the same

What's the best way to pass an optional argument that is nearly always the same? Case in point is Javascript's parseInt function; the second argument for radix is optional, but to avoid a string beginning with a zero being treated as octal, it is generally recognized good practice to always specify 10 as the second argument. Fair enou...

Why doesn't C++ have a pointer to member function type ?

I could be totally wrong here, but as I understand it, C++ doesn't really have a native "pointer to member function" type. I know you can do tricks with Boost and mem_fun etc. But why did the designers of C++ decide not to have a 64-bit pointer containing a pointer to the function and a pointer to the object, for example? What I mean s...

raise error within MySql function

Hi, I've created a MySql function and would like to raise an error if the values passed for the parameters are invalid. What are my options for raising an error within a MySql function? Thanks, Don ...

why do functions dont have parameterized return types, as it has parameterized input?

This always forces us to return a single parameter in case I need to return multiple, say a List and a String. This restriction is not there in function arguments. ...

JavaScript Collection of one-line Useful Functions

This is a question to put as many interesting and useful JavaScript functions written in one line as we can. I made this question because I'm curious how many people around like the art of one-Line programming in JavaScript, and I want to see their progress in action. Put variations of each code inside comments. ...

When is a function too long?

35 lines, 55 lines, 100 lines, 300 lines? When you should start to break it apart? I'm asking because I have a function with 60 lines (including comments) and was thinking about breaking it apart. long_function(){ ... } into: small_function_1(){...} small_function_2(){...} small_function_3(){...} The functions are not going to be u...

Regex to pull out C function prototype declarations?

I'm somewhere on the learning curve when it comes to regular expressions, and I need to use them to automatically modify function prototypes in a bunch of C headers. Does anyone know of a decent regular expression to find any and all function prototypes in a C header, while excluding everything else? Edit: Three things that weren't cle...

Array functions in jQuery

Hi, I am using jQuery in my web-app I want to use arrays, but I am not able to find out functions for arrays (add, remove or append elements in array) in jquery, Can anyone share with me any link related to jQuery array functions which will explain the jquery array functions. Thanks ...

function overloading in C

Is there any way to achieve function overloading in C? I am looking at simple functions to be overloaded like foo (int a) foo (char b) foo (float c , int d) I think there is no straight forward way, looking for workarounds if any? ...

What's a good weighting function?

I'm trying to perform some calculations on a non-directed, cyclic, weighted graph, and I'm looking for a good function to calculate an aggregate weight. Each edge has a distance value in the range [1,∞). The algorithm should give greater importance to lower distances (it should be monotonically decreasing), and it should assign the val...

Regarding JavaScript function unorthodoxy...

I've been programming for the Web for quite some time now, but have only just recently discovered a few new intricacies regarding the use of functions and the weird (or so I view them as) things you can do with them. However, they seem at this point only to be syntactically pretty things. I was hoping somebody might enlighten me as to ho...

How do you write tests to test functions with variable return values?

I've got a simple function like this: function CreateFileLink() { global $Username; return date("d-m-y-g-i"); } How do you write code to test a function like that where the return data is variable? ...

Getting a better understanding of callback functions in JavaScript

I understand passing in a function to another function as a callback and having it execute, but I'm not understanding the best implementation to do that. I'm looking for a very basic example, like this: var myCallBackExample = { myFirstFunction : function( param1, param2, callback ) { // Do something with param1 and param2. ...

How to declare a function in Cocoa after the function using it?

I'm slowly building my application to a working state. I'm using two functions called setCollection and addToCollection. These functions both accept NSArray as input. I also have a function called add in which I use both of these functions. When I try to compile, Xcode shows an error: 'setCollection' undeclared (first use in this f...

PHP: Suppress output within a function?

What is the simplest way to suppress any output a function might produce? Say I have this: function testFunc() { echo 'Testing'; return true; } And I want to call testFunc() and get its return value without "Testing" showing up in the page. Assuming this would be in the context of other code that does output other things, is t...

Basic C++ question regarding scope of functions

I'm just starting to learn C++ so you'll have to bear with my ignorance. Is there a way to to declare functions such that they can be referenced without being written before the function that uses them. I'm working with one cpp file (not my decision) and my functions call themselves so there is not really a proper order to place them in....

Why is dynamically modifying a JavaScript function's code mid-execution a bad thing?

A few days ago, I asked a question regarding dynamically modifying a function's code midway through the outerlying script's execution and I was told to completely forget ever coming upon the notion. I'm not sure I understand why that is. Let me give an example: <script> var display = function(msg) { alert(msg); } // Now, at the momen...