Search Results

Search found 9082 results on 364 pages for 'c functions'.

Page 45/364 | < Previous Page | 41 42 43 44 45 46 47 48 49 50 51 52  | Next Page >

  • Code equivalence between Javascript and PHP

    - by xdevel2000
    I'm trying to learn PHP and I wish to know if there are some function equivalence constructs: In JS I can do: var t = function() {}; t(); myObj.DoStuff = function() {} // here I add a method at run-time myObj.DoStuff(); myObj["DoStuff"](); var j = myObj.DoStuff; j(); and so other things with function evaluation. In Js objects are associative arrays so every properties is accessible with the subscript notation... Can I add a method at run-time to a class template so next its object instances can have it? In JS I can do that via a prototype function property.

    Read the article

  • C++ vs. C++/CLI: Const qualification of virtual function parameters

    - by James McNellis
    [All of the following was tested using Visual Studio 2008 SP1] In C++, const qualification of parameter types does not affect the type of a function (8.3.5/3: "Any cv-qualifier modifying a parameter type is deleted") So, for example, in the following class hierarchy, Derived::Foo overrides Base::Foo: struct Base { virtual void Foo(const int i) { } }; struct Derived : Base { virtual void Foo(int i) { } }; Consider a similar hierarchy in C++/CLI: ref class Base abstract { public: virtual void Foo(const int) = 0; }; ref class Derived : public Base { public: virtual void Foo(int i) override { } }; If I then create an instance of Derived: int main(array<System::String ^> ^args) { Derived^ d = gcnew Derived; } it compiles without errors or warnings. When I run it, it throws the following exception and then terminates: An unhandled exception of type 'System.TypeLoadException' occurred in ClrVirtualTest.exe Additional information: Method 'Foo' in type 'Derived'...does not have an implementation. That exception seems to indicate that the const qualification of the parameter does affect the type of the function in C++/CLI (or, at least it affects overriding in some way). However, if I comment out the line containing the definition of Derived::Foo, the compiler reports the following error (on the line in main where the instance of Derived is instantiated): error C2259: 'Derived': cannot instantiate abstract class If I add the const qualifier to the parameter of Derived::Foo or remove the const qualifier from the parameter of Base::Foo, it compiles and runs with no errors. I would think that if the const qualification of the parameter affects the type of the function, I should get this error if the const qualification of the parameter in the derived class virtual function does not match the const qualification of the parameter in the base class virtual function. If I change the type of Derived::Foo's parameter from an int to a double, I get the following warning (in addition to the aforementioned error, C2259): warning C4490: 'override': incorrect use of override specifier; 'Derived::Foo' does not match a base ref class method So, my question is, effectively, does the const qualification of function parameters affect the type of the function in C++/CLI? If so, why does this compile and why are there no errors or warnings? If not, why is an exception thrown?

    Read the article

  • Haskell FlatMap

    - by mvid
    I am a beginner interested in Haskell, and I have been trying to implement the flatmap (=) on my own to better understand it. Currently I have flatmap :: (t -> a) -> [t] -> [a] flatmap _ [] = [] flatmap f (x:xs) = f x : flatmap f xs which implements the "map" part but not the "flat". Most of the modifications I make result in the disheartening and fairly informationless Occurs check: cannot construct the infinite type: a = [a] When generalising the type(s) for `flatmap' error. What am I missing?

    Read the article

  • Is it possible to call a JavaScript function using an array of values as arguments ?

    - by Moshe Levine
    I'm looking for another way of doing the following: function call_any_function(func, parameters){ // func => any given function if(parameters.length==0){ func(); } if(parameters.length==1){ func(parameters[0]); } if(parameters.length==2){ func(parameters[0], parameters[1]); } if(parameters.length==3){ func(parameters[0], parameters[1], parameters[2]); } if(parameters.length==4){ func(parameters[0], parameters[1], parameters[2], parameters[3]); } // ... and so on }; It seems basic but I couldn't find an answer. Any ideas?

    Read the article

  • postgresql syntax while exists loop

    - by veilig
    I'm working at function from Joe Celkos book - Trees and Hierarchies in SQL for Smarties I'm trying to delete a subtree from an adjacency list but part my function is not working yet. WHILE EXISTS –– mark leaf nodes (SELECT * FROM OrgChart WHERE boss_emp_nbr = -99999 AND emp_nbr > -99999) LOOP –– get list of next level subordinates DELETE FROM WorkingTable; INSERT INTO WorkingTable SELECT emp_nbr FROM OrgChart WHERE boss_emp_nbr = -99999; –– mark next level of subordinates UPDATE OrgChart SET emp_nbr = -99999 WHERE boss_emp_nbr IN (SELECT emp_nbr FROM WorkingTable); END LOOP; my question: is the WHILE EXISTS correct for use w/ postgresql? I appear to be stumbling and getting caught in an infinite loop in this part. Perhaps there is a more correct syntax I am unaware of.

    Read the article

  • Get number of posts in a topic PHP

    - by Wayne
    How do I get to display the number of posts on a topic like a forum. I used this... (how very noobish): function numberofposts($n) { $sql = "SELECT * FROM posts WHERE topic_id = '" . $n . "'"; $result = mysql_query($sql) or die(mysql_error()); $count = mysql_num_rows($result); echo number_format($count); } The while loop of listing topics: <div class="topics"> <div class="topic-name"> <p><?php echo $row['topic_title']; ?></p> </div> <div class="topic-posts"> <p><?php echo numberofposts($row['topic_id']); ?></p> </div> </div> Although it is a bad method of doing this... All I need is to know what would be the best method, don't just point me out to a website, do it here, because I'm trying to learn much. Okay? :D Thanks.

    Read the article

  • PIG doesn't read my custom InputFormat

    - by Simon Guo
    I have a custom MyInputFormat that suppose to deal with record boundary problem for multi-lined inputs. But when I put the MyInputFormat into my UDF load function. As follow: public class EccUDFLogLoader extends LoadFunc { @Override public InputFormat getInputFormat() { System.out.println("I am in getInputFormat function"); return new MyInputFormat(); } } public class MyInputFormat extends TextInputFormat { public RecordReader createRecordReader(InputSplit inputSplit, JobConf jobConf) throws IOException { System.out.prinln("I am in createRecordReader"); //MyRecordReader suppose to handle record boundary return new MyRecordReader((FileSplit)inputSplit, jobConf); } } For each mapper, it print out I am in getInputFormat function but not I am in createRecordReader. I am wondering if anyone can provide a hint on how to hoop up my costome MyInputFormat to PIG's UDF loader? Much Thanks. I am using PIG on Amazon EMR.

    Read the article

  • JavaScript function, which reads connections between objects

    - by Nikita Sumeiko
    I have a JavaScript literal: var members = { "mother": { "name" : "Mary", "age" : "48", "connection": { "brother" : "sun" } }, "father": { "name" : "Bill", "age" : "50" }, "brother": { "name" : "Alex", "age" : "28" } } Than I have a function, which should read connections from the literal above. It looks like this: function findRelations(members){ var wires = new Array(); var count = 0; for (n = 0; n < members.length; n++){ alert(members.length); // this alert is undefined if (members[n].connection){ for (i = 0; i < members[n].connection[0].length; i++){ var mw = new Array(); var destination = 0; for (m = 0; m < members.length; m ++){ if (members[m] == members[n].connection[0]){ destination = m; mw = [n, destination]; wires [count] = mw; count++; } } } } } return wires; } However, when I run this function, I get nothing. And the first alert, which is placed inside the function shows 'undefined' at all. findRelations(members); alert("Found " + wires.length + " connections"); I guess that's because of JavaScript literal. Could you suggest how to change a function or perhaps to change litteral to JSON array to get it work?! And at the end to get 'm' and 'n' values as numbers.

    Read the article

  • Assigning document.getElementById to another function

    - by Andreas Grech
    I am trying to do the following in JavaScript: var gete = document.getElementById; But I am getting the following error (From FireBug's Console): uncaught exception: [Exception... "Illegal operation on WrappedNative prototype object" nsresult: "0x8057000c (NS_ERROR_XPC_BAD_OP_ON_WN_PROTO)" location: "JS frame :: http://localhost:8080/im_ass1/ :: anonymous :: line 15" data: no] Now obviously I can wrap the function as follows: var gete = function (id) { return document.getElementById(id); }; But what is the reason I'm getting the above exception when assigning the function to another name?

    Read the article

  • Need for prefixing a function with (void)...

    - by puffadder
    Hi All, I recently came across a rather unusual coding convention wherein the call for a function returning "void" is prefixed with (void). e.g. (void) MyFunction(); Is it any different from the function call like: MyFunction(); Has it got any advantage or is it yet another needless but there coding convention of some sort?

    Read the article

  • T-SQL: How Do I Create A "Private" Function Inside A Stored Procedure

    - by RPM1984
    Okay so im writing a SQL Server 2008 Stored Procedure (maintenance script). In doing so, being a good boy i've done plenty of error handling, checking rowcounts, printing output messages, etc But in doing this, ive found myself writing over and over again something like this: SELECT @RowsAffected = @@ROWCOUNT IF @RowsAffected > 0 BEGIN PRINT CAST(@RowsAffected, NVARCHAR(2)) + 'rows updated.' END Or debug messages like this: PRINT 'User ' + CAST(@UserId AS NVARCHAR(5)) + ' modified successfully' Is there a way i can create a kind of 'subroutine' inside the stored procedure (like a private method) that can accept something as a parameter (doesnt have to though) and do some logic? I want to be able to do something like this: CheckRowCounts Or this: PrintUserUpatedMessage(@UserId) Which would then perform the above logic (check rowcount, print message, etc) And yes obviously i can create a UDF, but then i would need to create/drop it etc as this logic is only required for the life of the execution of this stored procedure. Getting sick and tired of writing the same code over and over again, and changing all the different areas ive used it when i get an error =) Can anyone help?

    Read the article

  • deleting cookie at the end of a process

    - by RyanP13
    Hi, I am using the following plug in for cookies in jQuery: https://code.google.com/p/cookies/ The issue i am having is not with the plugin but when and how to delete the cookie at the end of a quoting process. The site i am using this on is a six step online quote and buy process. There is Omniture event serialisation sitestat tracking applied to some of the pages. This event serialisation has to include the name of the event and a random number of which i create. I have a generic function for this which i call at the bottom of the page like so: serialEvent('event21:', 'payment'); Here is the function: function serialEvent(eventNumber, eventName) { var sessionID = jaaulde.utils.cookies.get('sessionID'); var remLength = 20 - eventName.length; var remSession = sessionID.substr(sessionID.length - remLength, remLength); var eventName = eventName + remSession; s.events = eventNumber + eventName; } I need to delete the cookie at the end of the process, the Thank you page but i also need the cookie 'sessionID' for the 'serialEvent' function. As the function is called at the bottom of the page should i just write the cookie delete after it? Is that robust enough? I need to be sure that the function has successfully been called before the cookie is deleted. The code for deleting the cookie is quite simple: jaaulde.utils.cookies.del('sessionID'); Thanks :)

    Read the article

  • Arrays become null after passing to function in PHP

    - by William
    So when I pass my filled arrays to the function createform the form is created with $max_avatars options, but they have no name or value. Why are my arrays becoming null? <?php $avatar_image_name = array('hacker','samurai','cool','happy','thatsnice','angry','tv','bang'); $avatar_name = array('Hacker','Samurai','Cool','Happy','That\'s nice','Angry','TV','Bang'); $max_avatars = 6; createform($max_avatars, $avatar_image_name, $avatar_name); ?> The function createform: function createform($max_avatars, $avatar_image_name, $avatar_name) { $string ='<table id="formtable"> <tr><td class="formtext">Name:</td><td><input type="text" name=name size=25 /></td></tr> <tr><td class="formtext">Trip:</td><td><input type="text" name=trip size=25 /> (<font style="color: #ff0000">Don\'t use your password</font>)</td></tr> <tr><td class="formtext">Comment</td><td><textarea name=post rows="4" cols="50"></textarea></td></tr> <tr><td class="formtext">Avatar:</td> <td> <select name=avatar>'; for($i = 0; $i < $max_avatars; $i++){ $string = ($string . '<option value="'.$avatar_image_name[i].'">'.$avatar_name[i].'</option>'); } $string = ($string . '</select> </td> <tr><td class="formtext">Extra</td><td>Fortune: <input type="radio" name="extra" value="fortune" /> Poker: <input type="radio" name="extra" value="poker" /></td></tr> </table> <input type=submit value="Submit" id="submitbutton">'); echo $string; }

    Read the article

  • How to avoid timestamp issue in a long query?

    - by pingi
    Hi, I have the following 2 tables: items: id int primary key bla text events: id_items int num int when timestamp without time zone ble text composite primary key: id_items, num and want to select to each item the most recent event (the newest 'when'). I wrote an request, but I don't know if it could be written more efficiently. Also on PostgreSQL there is a issue with comparing Timestamp objects: 2010-05-08T10:00:00.123 == 2010-05-08T10:00:00.321 so I select with 'MAX(num)' Any thoughts how to make it better? Thanks. SELECT i.*, ea.* FROM items AS i JOIN ( SELECT t.s AS t_s, t.c AS t_c, max(e.num) AS o FROM events AS e JOIN ( SELECT DISTINCT id_item AS s, MAX(when) AS c FROM events GROUP BY s ORDER BY c ) AS t ON t.s = e.id_item AND e.when = t.c GROUP BY t.s, t.c ) AS tt ON tt.t_s = i.id JOIN events AS ea ON ea.id_item = tt.t_s AND ea.cas = tt.t_c AND ea.num = tt.o;

    Read the article

  • How do you solve this Haskell problem using a fold map and take?

    - by Linda Cohen
    Define a function replicate which given a list of numbers returns a list with each number duplicated its value. Use a fold, map, and take .. replicate [5,1,3,2,8,1,2] output: [5,5,5,5,5,1,3,3,3,2,2,8,8,8,8,8,8,8,8,1,2,2] I've figure this out using List comprehension and recursion: replicate2 [] = [] replicate2 (n:nn) = take n(repeat n) ++ replicate2 nn but how would you use fold and map to do this? so far I have: replicate n = map (foldl1 (take n(repeat n)) n) n which is obviously wrong, but I think I am close.. so any help would be nice, THANKS!

    Read the article

  • Javascript get Function Name?

    - by Scott
    How can I access a function name from inside that function? var my.namespace.myFunc = function() { this.getFn = function() { // access fully qualified name (ie "my.namespace.myFunc") } } var obj = new my.namespace.myFunc(); console.info(obj.getFn());

    Read the article

  • va_arg with pointers

    - by Yktula
    I want to initialize a linked list with pointer arguments like so: /* * Initialize a linked list using variadic arguments * Returns the number of structures initialized */ int init_structures(struct structure *first, ...) { struct structure *s; unsigned int count = 0; va_list va; va_start(va, first); for (s = first; s != NULL; s = va_arg(va, (struct structure *))) { if ((s = malloc(sizeof(struct structure))) == NULL) { perror("malloc"); exit(EXIT_FAILURE); } count++; } va_end(va); return count; } The problem is that clang errors type name requires a specifier or qualifier at va_arg(va, (struct structure *)), and says that the type specifier defaults to int. It also notes instantiated form at (struct structure *) and struct structure *. This, what seems to be getting assigned to s is int (struct structure *). It compiles fine when parentheses are removed from (struct structure *), but the structures that are supposed to be initialized are inaccessible. Why is int assumed when parentheses are around the type argument passed to va_arg? How can I fix this?

    Read the article

  • How to make some functions of a class as private for third level of inheritance.

    - by Shantanu Gupta
    I have created a class say A which has some functions defined as protected. Now Class B inherits A and class C inherits B. Class A has private default constructor and protected parameterized constructor. I want Class B to be able to access all the protected functions defined in Class A but class C can have access on some of the functions only not all the functions and class C is inheriting class B. How can I restrict access to some of the functions of Class A from Class C ? Class A { private A(){} protected A(int ){} protected calc(){} protected allow(){} } Class B : A {} // calc() and allow() should be accessible here CLass C:B { // calc() should not be accessible here but allow() should be accessible here. }

    Read the article

  • Non-graphical linearity estimation

    - by aL3xa
    In my previous post, I was looking for correlation ratio (η or η2) routines in R. I was surprised by the fact that no one uses η for linearity checking in the GLM procedures. Let's start form a simple example: how do you check linearity of bivariate correlation? Solely with scatterplot? There are several ways of doing this, one way is to compare linear and non-linear model R2, then to apply F test to seek for significant difference between them. Finally, the question is: How do you check linearity, the "non-grafical" way?

    Read the article

  • Why does this MySQL function return null?

    - by Shore
    Description: the query actually run have 4 results returned,as can be see from below, what I did is just concate the items then return, but unexpectedly,it's null. I think the code is self-explanatory: DELIMITER | DROP FUNCTION IF EXISTS get_idiscussion_ask| CREATE FUNCTION get_idiscussion_ask(iask_id INT UNSIGNED) RETURNS TEXT DETERMINISTIC BEGIN DECLARE done INT DEFAULT 0; DECLARE body varchar(600); DECLARE created DATETIME; DECLARE anonymous TINYINT(1); DECLARE screen_name varchar(64); DECLARE result TEXT; DECLARE cur1 CURSOR FOR SELECT body,created,anonymous,screen_name from idiscussion left join users on idiscussion.uid=users.id where idiscussion.iask_id=iask_id; DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; SET result = ''; OPEN cur1; REPEAT FETCH cur1 INTO body, created, anonymous, screen_name; SET result = CONCAT(result,'<comment><body><![CDATA[',body,']]></body>','<replier>',if(screen_name is not null and !anonymous,screen_name,''),'</replier>','<created>',created,'</created></comment>'); UNTIL done END REPEAT; CLOSE cur1; RETURN result; END | DELIMITER ; mysql> DELIMITER ; mysql> select get_idiscussion_ask(1); +------------------------+ | get_idiscussion_ask(1) | +------------------------+ | NULL | +------------------------+ 1 row in set (0.01 sec) mysql> SELECT body,created,anonymous,screen_name from idiscussion left join users on idiscussion.uid=users.id where idiscussion.iask_id=1; +------+---------------------+-----------+-------------+ | body | created | anonymous | screen_name | +------+---------------------+-----------+-------------+ | haha | 2009-05-27 04:57:51 | 0 | NULL | | haha | 2009-05-27 04:57:52 | 0 | NULL | | haha | 2009-05-27 04:57:52 | 0 | NULL | | haha | 2009-05-27 04:57:53 | 0 | NULL | +------+---------------------+-----------+-------------+ 4 rows in set (0.00 sec) For those who don't think the code is self-explanatory: Why the function returns NULL?

    Read the article

  • Advice/suggestions for my first project PHP Classes

    - by Philip
    Hi guys, Any advice is welcome! I have a very limited understanding of php classes but below is my starting point for the route I would like to take. The code is a reflection of what I see in my head and how I would like to go about business. Does my code even look ok, or am I way off base? What are your thoughts, how would you go about achieving such a task as form-validate-insertquery-sendmail-return messages and errors? Please try and keep your answers simple enough for me to digest as for me its about understanding whats going on and not just a copy/paste job. Kindest regards, Phil. Note: This is a base structure only, no complete code added. <?php //======================================= //class.logging.php //======================================== class logging { public $data = array(); public $errors = array(); function __construct() { array_pop($_POST); $this->data =($this->_logging)? is_isset(filterStr($_POST) : ''; foreach($this->data as $key=> $value) { $this->data[$key] = $value; } //print_r($this->data); de-bugging } public function is_isset($str) { if(isset($str)) ? true: false; } public function filterStr($str) { return preg_match(do somthing, $str); } public function validate_post() { try { if(!is_numeric($data['cardID'])) ? throw new Exception('CardID must be numeric!') : continue; } catch (Exception $e) { return $errors = $e->getCode(); } } public function showErrors() { foreach($errors as $error => $err) { print('<div class="notok"></div><br />'); } } public function insertQ() { $query = ""; } } //======================================= //Usercp.php //======================================== if(isset($_GET['mode'])) { $mode = $_GET['mode']; } else { $mode = 'usercp'; } switch($mode) { case 'usercp': echo 'Welcome to the User Control Panel'; break; case 'logging': require_once 'class.logging.php'; $logger = new logging(); if(isset($_POST['submit']) { if($logger->validate_post === true) { $logger->insertQ(); require_once '/scripts/PHPMailer/class.phpmailer.php'; $mailer = new PHPMailer(); $mailer->PHPMailer(); } else { echo ''.$logger->showErrors.''; } } else { echo ' <form action="'.$_SERVER['PHP_SELF'].'?mode=logging" method="post"> </form> '; } break; case 'user_logout': // do somthing break; case 'user_settings': // do somthing break; ?>

    Read the article

  • Creating a Function in SQL Server with a Phone Number as a parameter and returns a Random Number

    - by Emer
    Hi Guys, I am hoping someone can help me here as google is not being as forthcoming as I would have liked. I am relatively new to SQL Server and so this is the first function I have set myself to do. The outline of the function is that it has a Phone number varchar(15) as a parameter, it checks that this number is a proper number, i.e. it is 8 digits long and contains only numbers. The main character I am trying to avoid is '+'. Good Number = 12345678 Bad Number = +12345678. Once the number is checked I would like to produce a random number for each phone number that is passed in. I have looked at substrings, the like operator, Rand(), left(), Right() in order to search through the number and then produce a random number. I understand that Rand() will produce the same random number unless alterations are done to it but right now it is about actually getting some working code. Any hints on this would be great or even point me towards some more documentation. I have read books online and they haven't helped me, maybe I am not looking in the right places. Here is a snippet of code I was working on the Rand declare @Phone Varchar (15) declare @Counter Varchar (1) declare @NewNumber Varchar(15) set @Phone = '12345678' set @Counter = len(@Phone) while @Counter > 0 begin select case when @Phone like '%[0-9]%' then cast(rand()*100000000 as int) else 'Bad Number' end set @counter = @counter - 1 end return Thanks for the help in advance Emer

    Read the article

  • Does "Value Restriction" mean that there is no higher order functional programming?

    - by Sadache
    Does "Value Restriction" mean that there is no higher order functional programming? I have a problem that each time I try to do a bit of HOP I get caught by a VR error. Example: let simple (s:string)= fun rq->1 let oops= simple "" type 'a SimpleType= F of (int ->'a-> 'a) let get a = F(fun req -> id) let oops2= get "" and I would like to know whether it is a problem of a prticular implementation of VR or it is a general problem that has no solution in a mutable type-infered language that doesn't include mutation in the type system.

    Read the article

  • Is there a practical benefit to casting a NULL pointer to an object and calling one of its member fu

    - by zdawg
    Ok, so I know that technically this is undefined behavior, but nonetheless, I've seen this more than once in production code. And please correct me if I'm wrong, but I've also heard that some people use this "feature" as a somewhat legitimate substitute of a lacking aspect of the current C++ standard, namely, the inability to obtain the address (well, offset really) of a member function. For example, this is out of a popular implementation of a PCRE (Perl-compatible Regular Expression) library: #ifndef offsetof #define offsetof(p_type,field) ((size_t)&(((p_type *)0)->field)) #endif One can debate whether the exploitation of such a language subtlety in a case like this is valid or not, or even necessary, but I've also seen it used like this: struct Result { void stat() { if(this) // do something... else // do something else... } }; // ...somewhere else in the code... ((Result*)0)->stat(); This works just fine! It avoids a null pointer dereference by testing for the existence of this, and it does not try to access class members in the else block. So long as these guards are in place, it's legitimate code, right? So the question remains: Is there a practical use case, where one would benefit from using such a construct? I'm especially concerned about the second case, since the first case is more of a workaround for a language limitation. Or is it? PS. Sorry about the C-style casts, unfortunately people still prefer to type less if they can.

    Read the article

< Previous Page | 41 42 43 44 45 46 47 48 49 50 51 52  | Next Page >