function

passing functions

Ok, it's been a while since I wrote in C++. and I've never done anything quiet this high level. So basically I need to create a class. The constructor for the class needs to take a reference (or pointer) to a method form another class, or to a function. Basically I have a class that needs to on occasion read a value from a fltk valuato...

write a c function that generates one random number, or a pair of random numbers, or a triplet of random numbers given the particular ranges.

i have to generate random numbers for 3 different cases. i. 1 dice ii. a pair of dice iii. 3 dices my questions: 1. please suggest me sm good logic to generate random numbers for all the 3 cases. 2. does the logic change when i consider the cses of 2 dices, rather than 1? 3.how much of an effect does the range in which we have to genrate...

How can I dispose SharePoint objects safely in PowerShell functions?

What is the proper way of disposing objects created inside a function? I came across this method on a website. function get-spweb ([String]$webUrl=$(throw 'Parameter -webUrl is missing!')) { $site = get-SPSite $weburl return $site.OpenWeb() $site.Dispose() } Does the Dispose method ever get called in this function? ...

How to pass a string to a function in Objective-C

I made a method like this: -(void) doSomething:(NSString *)str { } I call it like this doSomething(foo); It doesn't work. ...

Javascript parses in some way the string parameters of functions?

When I try to pass a string to a function like so i="file:///bla/bla/bla"; Fade(i); i get Uncaught SyntaxError: Unexpected token : so i tried passing a literal in the function like f("img1.jpg"); and i got Uncaught ReferenceError: img1 is not defined (anonymous function) What is going on? (note that i am kind of new in js) In pa...

What is ellipsis operator in c

Possible Duplicate: What's does mean in an argument list in C ? function fun1(...) { } Please tell me about what is the use and how to use ellipsis operator in c. Thanks, ...

How to make function return string in c++

Possible Duplicate: How to convert this code to use string I have a function like this: char *foo() { } How can I make it return a string instead? I tried string foo() { } but the compiler complains. ...

what is the difference between friend function and friend class?

what is the difference between friend function and friend class? and where should be use of friend keyword? ...

How to make this function recursive

void print_combinations(const std::string &str) { int i, j, k; int len = str.length(); for (i = 0; i < len - 2; i++) { for (j = i + 1; j < len - 1; j++) { for (k = j + 1; k < len; k++) // show combination ...

display the mysql count function?

$query = "select count(*) from relationships where leader = 'user_id'"; $result = mysql_query($query); how can i display the count? thanks ...

javascript function return data

I have a function like this that does an ajax call to grab some data from a database. function db (content) { $.post('/ajax/db.php', { operation:operation, content:content }, function(data) { console.log(data); return data; }); } console.log(data); ...

C++: Trouble Using String as Argument of a Function

Okay, I am having trouble with the following piece of code (in a header file): #ifndef XML_H_INCLUDED #define XML_H_INCLUDED #include "libxml/parser.h" #include "libxml/xmlwriter.h" #include <string> class XmlFile{ public: XmlFile(string filename){ file = xmlParseFile(filename); } xmlDocPtr file; //Pointer to xml...

C++ Passing Pointer to Function (Howto) + C++ Pointer Manipulation

I am a little confused as to how passing pointers works. Let's say I have the following function and pointer, and... EDIT: ...I want to use a pointer to some object as an argument in the function. i.e.: void Fun(int Pointer){ int Fun_Ptr = ---Passed Pointer---; //So that Fun_Ptr points to whatever ---Passed Pointer points...

What does this line of code do?

void expand_combinations(const char *remaining_string, string const & s, int rema in_depth) { if(remain_depth==0) { std::cout << s << std::endl; return; } for(int k=0; k < strlen(remaining_string); ++k) { string str(s); str.append(1, remaining_string[k]); expand_combinations(re...

What's going on in JavaScript when I use the "traditional" C-style function declaration?

I know that there are several ways to define a function in JavaScript. Two of the most common ones are: (1) function add (a, b) { return a + b; } (2) var add = function (a, b) { return a + b; } I am comfortable with the idea of a function as an object that can be passed around just like any other variabl...

Function constructor vs function statement

Hi, today I've read we have a way of declaring the function by Function constructor. But I never seen the actual implementation that uses Function constructor in real. So I would like to ask, are there any circumstances that we can get benefit by using Function constructor as opposed to using function() declaration? And what are the hidd...

Python function help

Please help! cannot figure this out for the life of me Given the function f(x,n)= n**x(n-1) 5c. Using this function, calculate the rate of change of (((2^3 + 3^2)^4 -2^4)^2 + (3^4 – (6^2 + 3)^4)^3)^3 This is what I came up with in IDLE: def function(x, n): return (n*(x**(n-1))) assertEqual ( function (((( function ...

how to pass variable to jquery event?

$(".addcart").click(function(){ $("input[name='items']:checked").each(function() { //doing something }); }); I'm trying to create a common class onclick of which I'm doing something. Is there a way I can make "items" a variable, I mean Can I pass checkbox name to this event. ...

Question about const_cast in c++

Hi,all: this is quoted from Effective C++ 3rd editiion const_cast is typically used to cast away the constness of objects. It is the only C++-style cast that can do this. My question is can const_cast add constness to a non-const object? Actually i wrote a small programme trying to approve my thought. class ConstTest { public:...

Is there a gentle hash function tutorial?

Embarrassingly, picking a hash function (say, for hashing strings, or sets of integers, etc.) is still magic to me: take some prime numbers here, magic constants there, do some bit shifting, modulo something, and done. Is there a nice, gentle and approachable tutorial about creating hash functions? ...