function

Do I need to use dynamic_cast when calling a function that accepts the base class?

I have some classes like this: interface class IA { }; interface class IB { }; public ref class C : public IA, public IB { }; public ref class D { void DoSomething(IA^ aaa) { } void Run() { C^ bob = gcnew C(); DoSomething(dynamic_cast<IA^>(bob)); // #1 DoSomething(bob); // #2 } }; At the moment I always try to use dy...

Named arguments in Mathematica.

What's the best/canonical way to define a function with optional named arguments? To make it concrete, let's create a function foo with named arguments a, b, and c, which default to 1, 2, and 3, respectively. For comparison, here's a version of foo with positional arguments: foo[a_:1, b_:2, c_:3] := bar[a,b,c] Here is sample input a...

[PHP] Only allowing certain characters in string

Hi, I have been looking for a way to create a function to check if a string contains anything other than lower case letters and numbers in it, and if it does return false. I have searched on the internet but all I can find is old methods that require you to use functions that are now deprecated in PHP5. So how do we do it in PHP5? ...

When to use function-like macros in C

Hi, I was reading some code written in C this evening, and at the top of the file was the function-like macro HASH: #define HASH(fp) (((unsigned long)fp)%NHASH) This left me wondering, why would somebody choose to implement a function this way using a function-like macro instead of implementing it as a regular vanilla C function? Wha...

function implementation in : file.h vs in file.cxx

Hi My question is very simple , I am working on a old legacy code where most of function are implemented in header file only. As per my knowledge, Compiler convert function implemented in header into inline functions. I wanted to know if i move these implementation into .cxx file , What will be benefits ? Thanks in Advance ~SS ...

iterate through nested form elements in jquery

Hi! im sorry if this was posted already i have been looking to no avail.. I just want to know how to loop through nested form 'elements' (elements being not only the strict form elements like input tags but other html elements as well) in jquery. Currently i have this piece of code to do it: $('#'+arguments[i].formid).children().each(...

jquery $.function()

how can i write a plugin/function and then be able to call it like this(no selector required) $.function() noe i write my plugins something like this: (function($){ $.fn.extend({ //function name myFunction : function(){ //........... } }); })(jQuery); ...

PHP Class arguments in functions

Hi, I'm having trouble using an argument from my class in one of that class's functions. I have a class called company: class company { var $name; function __construct($name) { echo $name; } function name() { echo $name; } } $comp = new company('TheNameOfSomething'); $comp->name(); When I instantiate...

PHP function call from form not working

Guys, I'm trying to call a function from a form within the same .php file, but when the Submit button is hit, the table doesn't get generated. Here's the code: <p> <?php function selectQuery() { $con = mysql_connect("localhost","readonly",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_s...

Calling a UDF in LINQ without "dbo" database user

Hi every one! I am using LINQ to call a function named "GetTabMenuTheme", I dragged it in the Database Model to generate the function like this: [Function(Name="dbo.GetTabMenuTheme", IsComposable=true)] public string GetTabMenuTheme([Parameter(DbType="NVarChar(MAX)")] string state) { return ((string)(this.ExecuteMethodCall(this, ((...

PHP: use default value when calling a function.

in PHP you can call a function. by not calling all parameters by using these statement. function test($t1 ='test1',$t2 ='test2',$t3 ='test3') { echo "$t1, $t2, $t3"; } and you can just use the function like this test(); lets just say I want the last one to be different but not the others. the only way i know is by doing this with n...

Writing your own square root function.

How do you write your own function for finding the most accurate square root of an integer? After googling it, I found this, but firstly, I didn't get it completely, and secondly, it is approximate too. Assume square root as nearest integer (to the actual root) or a float. ...

Looping through an array of arrays, changing output on a given line(s)

This is what im using to loop through an array of arrays. $csvpre = explode("###", $data); $i = 0; $bgc = 0; foreach ( $csvpre AS $key => $value){ $info = explode("%%", $value); $i++; if($i == "1"){ echo "<tr bgcolor=#efefef><td></td>"; foreach ( $info as $key => $value ){ echo "<td>$value</td>"; } ...

Should functions return null or an empty object?

What is the best practice when returning data from functions. Is it better to return a Null or an empty object? And why should one do one over the other? Consider this: public UserEntity GetUserById(Guid userId) { //Imagine some code here to access database..... //Check if data was returned and return a null if none found ...

Are named functions underrated in JavaScript?

Taking the jQuery framework for example, if you run code like this: $(document).ready(function init() { foo.bar(); }); The stack trace you get in Firebug will look like this: init() anonymous() anonymous([function(), init(), function(), 4 more...], function(), Object name=args) anonymous() anonymous() As you can see, it's not very ...

Using a php function using a variable with delimiters

I would like to know If I can use a php function on a variable that contains delimiters like ' or ". I'm receiving a text content from my database and I would like to use: strip_tags($desc); on it but it does not work. Here is an example of what it can contain using var dump: string(1039) ""txt <a href=""/txt.php"" class=""txt"">txt</a...

PHP function inside function.

This code produces the result as 56. function x ($y) { function y ($z) { return ($z*2); } return($y+3); } $y = 4; $y = x($y)*y($y); echo $y; Any idea what is going inside? I am confused. ...

How to get the greatest of two columns values in MySQL?

I'm trying to do something like this: SELECT MAX( ADDDATE(expirationdate, INTERVAL 1 YEAR), ADDDATE(now(), INTERVAL 1 YEAR) ) That is, get "a year from now", or "a year from the expiration date stored in the table", whichever is greater (i'm renewing people's subscriptions). This obviously doesn't work, since MAX() is for aggrega...

C++, Accept lowercase and uppercase letters in a variable.

I want to allow the user to use lowercase or uppercase letters giving the value to the char type variable... Any help?? ...

Jquery functions in array

Hello evryone. I have a litle problem with my Javascript functions. It might be a litle deep into my code as well but im prety sure someone on Stackoverflow know the awnser! Ok first i have a PHP session that i use to save my image id's Then i have a page that shows 5 images at a time with a JQuery Click fonction to browse my images ...