Search Results

Search found 40165 results on 1607 pages for 'function pointers'.

Page 23/1607 | < Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >

  • js function to get filename from url

    - by Blankman
    Hi, I have a url like http://www.example.com/blah/th.html I need a javascript function to give me the 'th' value from that. All my urls have the same format (2 letter filenames, with .html extension). I want it to be a safe function, so if someone passes in an empty url it doesn't break. I know how to check for length, but I should be checking for null to right?

    Read the article

  • C++ boost function overloaded template

    - by aaa
    I cannot figure out why this segment gives unresolved overloaded function error (gcc version 4.3.4 (Debian 4.3.4-6)): #include <algorithm> #include <boost/function.hpp> int main { typedef boost::function2<const int&, const int&, const int&> max; max m(static_cast<max>(&std::max<int>)); } can you help me, thanks

    Read the article

  • Arguments to JavaScript Anonymous Function

    - by Phonethics
    for (var i = 0; i < somearray.length; i++) { myclass.foo({'arg1':somearray[i][0]}, function() { console.log(somearray[i][0]); }); } How do I pass somearray or one of its indexes into the anonymous function ? somearray is already in the global scope, but I still get somearray[i] is undefined

    Read the article

  • c++ Function pointer inlining

    - by wb
    I know I can pass a function pointer as a template parameter and get a call to it inlined but I wondered if any compilers these days can inline an 'obvious' inline-able function like: inline static void Print() { std::cout << "Hello\n"; } .... void (*func)() = Print; func(); Under Visual Studio 2008 its clever enough to get it down to a direct call instruction so it seems a shame it can't take it a step further?

    Read the article

  • TSQL, Rename column of a returning table in user Function

    - by user1433660
    I have defined function which returns table with 2 columns. Can I rename these columns so that resulting table would be like: Press name | Sum of pages ? CREATE FUNCTION F_3 (@press nvarchar(255)) RETURNS @table TABLE ( Press nvarchar(255), PagesSum int ) AS BEGIN INSERT @table SELECT @press, SUM(Books.Pages) FROM Books, Press WHERE Press.Name = @press AND Books.Id_Press = Press.Id GROUP BY Press.Name RETURN END GO SELECT * FROM F_3('BHV') GO I've tried to do it like Press AS 'Press name' nvarchar(255) but that won't work.

    Read the article

  • Passing template into boost function

    - by Ockonal
    template <class EventType> class IEvent; class IEventable; typedef boost::function<void (IEventable&, IEvent&)> behaviorRef; What is the right way for passing template class IEvent into boost function? With this code I get: error: functional cast expression list treated as compound expression error: template argument 1 is invalid error: invalid type in declaration before ‘;’ token

    Read the article

  • Function currying in Javascript

    - by kerry
    Do you catch yourself doing something like this often? 1: Ajax.request('/my/url', {'myParam': paramVal}, function() { myCallback(paramVal); }); Creating a function which calls another function asynchronously is a bad idea because the value of paramVal may change before it is called.  Enter the curry function: 1: Function.prototype.curry = function(scope) { 2: var args = []; 3: for (var i=1, len = arguments.length; i < len; ++i) { 4: args.push(arguments[i]); 5: } 6: var m = this; 7: return function() { 8: m.apply(scope, args); 9: }; 10: } This function creates a wrapper around the function and ‘locks in’ the method parameters.  The first parameter is the scope of the function call (usually this or window).  Any remaining parameters will be passed to the method call.  Using the curry method the above call changes to: 1: Ajax.request('/my/url', {'myParam': paramVal}, myCallback.curry(window,paramVal)); Remember when passing objects to the curry method that the objects members may still change.

    Read the article

  • Compute if a function is pure

    - by Oni
    As per Wikipedia: In computer programming, a function may be described as pure if both these statements about the function hold: The function always evaluates the same result value given the same argument value(s). The function result value cannot depend on any hidden information or state that may change as program execution proceeds or between different executions of the program, nor can it depend on any external input from I/O devices. Evaluation of the result does not cause any semantically observable side effect or output, such as mutation of mutable objects or output to I/O devices. I am wondering if it is possible to write a function that compute if a function is pure or not. Example code in Javascript: function sum(a,b) { return a+b; } function say(x){ console.log(x); } isPure(sum) // True isPure(say) // False

    Read the article

  • Why to say, my function is of IFly type rather than saying it's Airplane type

    - by Vishwas Gagrani
    Say, I have two classes: Airplane and Bird, both of them fly. Both implement the interface IFly. IFly declares a function StartFlying(). Thus both Airplane and Bird have to define the function, and use it as per their requirement. Now when I make a manual for class reference, what should I write for the function StartFlying? 1) StartFlying is a function of type IFly . 2) StartFlying is a function of type Airplane 3) StartFlying is a function of type Bird. My opinion is 2 and 3 are more informative. But what i see is that class references use the 1st one. They say what interface the function is declared in. Problem is, I really don't get any usable information from knowing StartFlying is IFly type. However, knowing that StartFlying is a function inside Airplane and Bird, is more informative, as I can decide which instance (Airplane or Bird ) to use. Any lights on this: how saying StartFlying is a function of type IFly, can help a programmer understanding how to use the function?

    Read the article

  • Pointers to implementing a taxonomy system?

    - by petsagouris
    I am taking part in the development of a PHP CMS (yeah I know you are like, meeh). It is currently using simple tags for tagging content. What I want to do is push the whole thing to using Taxonomy but I am not sure on what to pay attention to, or how to go about structuring the whole vocabularies/terms. I'd love to be able to keep the user interaction close to that of the current simple tags and at the same time allow for more advanced usage by power users. The Drupal and the Wordpress taxonomy systems are being reviewed at the moment and they provide valuable resources. Nevertheless, it could be that someone has some simpler and more appropriate thoughts on this matter.

    Read the article

  • How to create a variadic (with variable length argument list) function wrapper in JavaScript

    - by U-D13
    The intention is to build a wrapper to provide a consistent method of calling native functions with variable arity on various script hosts - so that the script could be executed in a browser as well as in the Windows Script Host or other script engines. I am aware of 3 methods of which each one has its own drawbacks. eval() method: function wrapper () { var str = ''; for (var i=0; i<arguments.lenght; i++) str += (str ?', ':'') + ',arguments['+i+']'; return eval('[native_function] ('+str+')'); } switch() method: function wrapper () { switch (arguments.lenght) { case 0: return [native_function] (arguments[0]); break; case 1: return [native_function] (arguments[0], arguments[1]); break; ... case n: return [native_function] (arguments[0], arguments[1], ... arguments[n]); } } apply() method: function wrapper () { return [native_function].apply([native_function_namespace], arguments); } What's wrong with them you ask? Well, shall we delve into all the reasons why eval() is evil? And also all the string concatenation... Not a solution to be labeled "elegant". One can never know the maximum n and thus how many cases to prepare. This also would strech the script to immense proportions and sin against the holy DRY principle. The script could get executed on older (pre- JavaScript 1.3 / ECMA-262-3) engines that don't support the apply() method. Now the question part: is there any another solution out there?

    Read the article

  • Concatenate javascript to a string/parameter in a function

    - by Gerry S
    I am using kottke.org's old JAH example to return some html to a div in a webpage. The code works fine if I use static text. However I need to get the value of a field to add to the string that is getting passed as the parameter to the function. var xmlhttp=false; /*@cc_on @*/ /*@if (@_jscript_version >= 5) try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } @end @*/ if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { xmlhttp = new XMLHttpRequest(); } function getMyHTML(serverPage, objID) { var obj = document.getElementById(objID); xmlhttp.open("GET", serverPage); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { obj.innerHTML = xmlhttp.responseText; } } xmlhttp.send(null); } And on the page.... <a href="javascript://" onclick="getMyHTML('/WStepsDE?open&category="+document.getElementById('Employee').value;+"','goeshere')">Change it!</a></p> <div id ="goeshere">Hey, this text will be replaced.</div> It fails (with the help of Firebug) with the getMyHTML call where I try to get the value of Employee to include in the first parameter. The error is "Unterminated string literal". Thx in advance for your help.

    Read the article

  • PHP Function parameters - problem with var not being set

    - by Marty
    So I am obviously not a very good programmer. I have written this small function: function dispAdjuggler($atts) { extract(shortcode_atts(array( 'slot' => '' ), $atts)); $adspot = ''; $adtype = ''; // Get blog # we're on global $blog_id; switch ($blog_id) { case 1: // root blog HOME page if (is_home()) { switch ($slot) { case 'top_leaderboard': $adspot = '855525'; $adtype = '608934'; break; case 'right_halfpage': $adspot = '855216'; $adtype = '855220'; break; case 'right_med-rectangle': $adspot = '858222'; $adtype = '613526'; break; default: throw new Exception("Ad slot is not defined"); break; } When I reference the function on a page like so: <?php dispAdjuggler("top_leaderboard"); ?> The switch is throwing the default exception. What am I doing wrong here? Thanks!!

    Read the article

  • remove duplicated array values in a function PHP

    - by Deividas Juškevicius
    I read all topics related to this question in stackoverflow and whole internet and cant find working sollution... Each owner has his item and when someone buy his item, owner gets an confirmation email, but when in cart is few same owner items, he gets several same email letters, so I need to remove dublicated array entries. I have tried to use DISTINCT and array_uniques functions but no luck. Any advices? I have an array and function to send mail.. function email($mail_array) { foreach(array_unique($mail_array) as $field => $value) { $result = mysql_query("select email from users where $field='$value'"); $row = mysql_fetch_array($result); $maail = mysql_real_escape_string($row['email']); $email_to = "".$maail.""; // rest of mail formatting code // create email headers $headers = 'From: '.$email_from."\r\n" . 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); } for ($i = 0; $i < $max; $i++) { $pid = $_SESSION['cart'][$i]['productid']; $owner = get_owner($pid); $mail_array = array( 'name' => $owner ); email($mail_array) //call function to send mail }

    Read the article

  • Function Returning Negative Value

    - by Geowil
    I still have not run it through enough tests however for some reason, using certain non-negative values, this function will sometimes pass back a negative value. I have done a lot of manual testing in calculator with different values but I have yet to have it display this same behavior. I was wondering if someone would take a look at see if I am missing something. float calcPop(int popRand1, int popRand2, int popRand3, float pERand, float pSRand) { return ((((((23000 * popRand1) * popRand2) * pERand) * pSRand) * popRand3) / 8); } The variables are all contain randomly generated values: popRand1: between 1 and 30 popRand2: between 10 and 30 popRand3: between 50 and 100 pSRand: between 1 and 1000 pERand: between 1.0f and 5500.0f which is then multiplied by 0.001f before being passed to the function above Edit: Alright so after following the execution a bit more closely it is not the fault of this function directly. It produces an infinitely positive float which then flips negative when I use this code later on: pPMax = (int)pPStore; pPStore is a float that holds popCalc's return. So the question now is, how do I stop the formula from doing this? Testing even with very high values in Calculator has never displayed this behavior. Is there something in how the compiler processes the order of operations that is causing this or are my values simply just going too high? If the later I could just increase the division to 16 I think.

    Read the article

  • Passing data to a jQuery click() function

    - by jakenoble
    Hi I have a simple span like so <span class="action removeAction">Remove</span> This span is within a table, each row has a remove span. And then I call a URL using AJAX when that span is clicked. The AJAX event needs to know the ID of the object for that row? What is the best way of getting that ID into the click function? I thought I could do something like this <span class="action removeAction" id="1">Remove</span> But an ID should not start with a number? Right? Then I thought I could do <span class="action removeAction" id="my1">Remove</span> Then just strip the 'my' part from the ID, but that just seems Yuk! Below is my click event and where my AJAX event is. <script type="text/javascript" language="text/javascript"> $(document).ready(function() { $(".removeAction").click(function() { //AJAX here that needs to know the ID } }); </script> I am sure there is a nice way of doing this? Thanks. Jake.

    Read the article

  • Fire Box doesnot support program based calling function

    - by manish
    on clicking any row of the following program... i am firinf on function mail file click....function just having alert message that shoes deffrent file name on the bases of clicking... *its working properly in IE .....FireBox N other browser function doesnot call on clicking on any row.. whats problem..please help me......i am writing code for your better awareness* For Each info In fsi Response.Write("<span id=" & " 'userijd'" & " onmouseup=" & "mailfileclick('" & info.Name & "')" & ";>") Response.Write("<td width=" & "16%" & " bgcolor=" & "#FFFFFF" & " style=" & "border-bottom-style:&nbsp;solid;&nbsp;border-bottom-width:&nbsp;1px" & " bordercolor=" & "#C0C0C0" & " nowrap" & ">") Response.Write("<font face=" & "Arial" & "style=" & "font-size:&nbsp;9pt" & " color=" & "#000000" & ">" & Mid(contents, InStr(contents, "Date: ") + Len("Date:"), 17) & "</font></td>") Response.Write("</span>") Next

    Read the article

  • Work with function references

    - by Ockonal
    Hello, I have another one question about functions reference. For example, I have such definition: typedef boost::function<bool (Entity &handle)> behaviorRef; std::map< std::string, ptr_vector<behaviorRef> > eventAssociation; The first question is: how to insert values into such map object? I tried: eventAssociation.insert(std::pair< std::string, ptr_vector<behaviorRef> >(eventType, ptr_vector<behaviorRef>(callback))); But the error: no matching function for call to ‘boost::ptr_vector<boost::function<bool(Entity&)> >::push_back(Entity::behaviorRef&)’ And I undersatnd it, but can't make workable code. The second question is how to call such functions? For example, I have one object of behaviorRef, how to call it with boost::bind with passing my own values?

    Read the article

  • 2 dimensional arrays passed to a function in c++

    - by John Marcus
    I'm working on doing calculations in a two dimensional array but keep getting a nasty error. i call the function by : if(checkArray(array)) and try to pass it in like this: bool checkArray(double array[][10]) //or double *array[][10] to no avail the error is error: cannot convert ‘double ()[(((unsigned int)(((int)n) + -0x00000000000000001)) + 1)]’ to ‘double’ for argument ‘1’ to ‘bool checkArray(double*)’ code snippet //array declaration int n = 10; double array[n][n]; //function call to pass in array while(f != 25) { cout<<endl; cout<<endl; if(checkArray(array)) //this is the line of the error { cout<<"EXIT EXIT EXIT"<<endl; } f++; } //function declaration bool checkArray(double *array)//, double newArray[][10]) { double length = sizeof(array); for(int i = 0; i < length; i++) for(int j = 0; j < length;j++) { double temp = array[i][j]; } }

    Read the article

  • Template problems: No matching function for call

    - by Nick Sweet
    I'm trying to create a template class, and when I define a non-member template function, I get the "No matching function for call to randvec()" error. I have a template class defined as: template <class T> class Vector { T x, y, z; public: //constructors Vector(); Vector(const T& x, const T& y, const T& z); Vector(const Vector& u); //accessors T getx() const; T gety() const; T getz() const; //mutators void setx(const T& x); void sety(const T& y); void setz(const T& z); //operations void operator-(); Vector plus(const Vector& v); Vector minus(const Vector& v); Vector cross(const Vector& v); T dot(const Vector& v); void times(const T& s); T length() const; //Vector<T>& randvec(); //operators Vector& operator=(const Vector& rhs); friend std::ostream& operator<< <T>(std::ostream&, const Vector<T>&); }; and the function in question, which I've defined after all those functions above, is: //random Vector template <class T> Vector<double>& randvec() { const int min=-10, max=10; Vector<double>* r = new Vector<double>; int randx, randy, randz, temp; const int bucket_size = RAND_MAX/(max-min +1); temp = rand(); //voodoo hackery do randx = (rand()/bucket_size)+min; while (randx < min || randx > max); r->setx(randx); do randy = (rand()/bucket_size)+min; while (randy < min || randy > max); r->sety(randy); do randz = (rand()/bucket_size)+min; while (randz < min || randz > max); r->setz(randz); return *r; } Yet, every time I call it in my main function using a line like: Vector<double> a(randvec()); I get that error. However, if I remove the template and define it using 'double' instead of 'T', the call to randvec() works perfectly. Why doesn't it recognize randvec()? P.S. Don't mind the bit labeled voodoo hackery - this is just a cheap hack so that I can get around another problem I encountered.

    Read the article

  • C++ function will not return

    - by Mike
    I have a function that I am calling that runs all the way up to where it should return but doesn't return. If I cout something for debugging at the very end of the function, it gets displayed but the function does not return. fetchData is the function I am referring to. It gets called by outputFile. cout displays "done here" but not "data fetched" I know this code is messy but can anyone help me figure this out? Thanks //Given an inode return all data of i_block data char* fetchData(iNode tempInode){ char* data; data = new char[tempInode.i_size]; this->currentInodeSize = tempInode.i_size; //Loop through blocks to retrieve data vector<unsigned int> i_blocks; i_blocks.reserve(tempInode.i_blocks); this->currentDataPosition = 0; cout << "currentDataPosition set to 0" << std::endl; cout << "i_blocks:" << tempInode.i_blocks << std::endl; int i = 0; for(i = 0; i < 12; i++){ if(tempInode.i_block[i] == 0) break; i_blocks.push_back(tempInode.i_block[i]); } appendIndirectData(tempInode.i_block[12], &i_blocks); appendDoubleIndirectData(tempInode.i_block[13], &i_blocks); appendTripleIndirectData(tempInode.i_block[14], &i_blocks); //Loop through all the block addresses to get the actual data for(i=0; i < i_blocks.size(); i++){ appendData(i_blocks[i], data); } cout << "done here" << std::endl; return data; } void appendData(int block, char* data){ char* tempBuffer; tempBuffer = new char[this->blockSize]; ifstream file (this->filename, std::ios::binary); int entryLocation = block*this->blockSize; file.seekg (entryLocation, ios::beg); file.read(tempBuffer, this->blockSize); //Append this block to data for(int i=0; i < this->blockSize; i++){ data[this->currentDataPosition] = tempBuffer[i]; this->currentDataPosition++; } data[this->currentDataPosition] = '\0'; } void outputFile(iNode file, string filename){ char* data; cout << "File Transfer Started" << std::endl; data = this->fetchData(file); cout << "data fetched" << std::endl; char *outputFile = (char*)filename.c_str(); ofstream myfile; myfile.open (outputFile,ios::out|ios::binary); int i = 0; for(i=0; i < file.i_size; i++){ myfile << data[i]; } myfile.close(); cout << "File Transfer Completed" << std::endl; return; }

    Read the article

  • Pipelined function calling another pipelined function.

    - by René Nyffenegger
    Here's a package with two pipelined functions: create or replace type tq84_line as table of varchar2(25); / create or replace package tq84_pipelined as function more_rows return tq84_line pipelined; function go return tq84_line pipelined; end tq84_pipelined; / Ant the corresponding package body: create or replace package body tq84_pipelined as function more_rows return tq84_line pipelined is begin pipe row('ist'); pipe row('Eugen,'); return; end more_rows; function go return tq84_line pipelined is begin pipe row('Mein'); pipe row('Name'); /* start */ for next in ( select column_value line from table(more_rows) ) loop pipe row(next.line); end loop; /* end */ pipe row('ich'); pipe row('weiss'); pipe row('von'); pipe row('nichts.'); end go; end tq84_pipelined; / The important thing is that go sort of calls more_rows with the for next in ... between /* start */ and /* end */ I can use the package as follows: select * from table(tq84_pipelined.go); This is all fine and dandy, but I hoped I could replace the lines between /* start */ and /* end */ with a simple call of more_rows. However, this is obviously not possible, as it generetes a PLS-00221: 'MORE_ROWS' is not a procedure or is undefined. So, my question: is there really no way to shortcut the loop?

    Read the article

< Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >