syntax

Why using namespace std is necessary here?

#include <iostream> using namespace std; int main() { cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!! return 0; } If I remove the 2nd statement,the build will fail. Why is it necessary? ...

"Directly accessing" return values without referencing

Look at this ruby example: puts ["Dog","Cat","Gates"][1] This will output Cat as ruby allows me to directly access the "anonymous" array created. If I try this in PHP, however: echo array("Dog","Cat,"Gates")[1] This won't work. What is this called, not only concerning arrays but all functions? Where else is it possible? Feel f...

How do I add on multiple $_POST['row'] and variables?

I am struggling to find out the syntactically correct way in which to add on more variables and rows to these statements: /* WANT TO ADD ON FIVE MORE $_POST[''] */ if(isset($_POST['check_prof']) && $_POST['check_prof'] == 'checked') { $check_prof = "checked"; }else{ $check_prof = "unchecked"; } /* SAME HERE, WANT TO ADD THE OTHER FI...

Rails: when to use self.

I am developing a Rails application and would like to understand when to use self.for. Here is the code of a method that I would like to fully understand. If it is possible I would like to have an alternative to this code so it would make things more clear. def self.for(facebook_id) User.create_by_facebook_id(facebook_id) end ...

How does extern work in c++?

This is from the <iostream>: namespace std { extern istream cin; ///< Linked to standard input extern ostream cout; ... It seems by using extern the data types defined in other namespaces will just be available? ...

Understanding extern in c++

namespace std { extern istream cin; ... } By using extern we declare that cin is defined in some other unit as the answer But what if istream is defined/undefined in std,there should be some difference,right? What is the difference for the compilor? ...

What's the equivalent of the bash in windows batch?

while [1 = 1] do eject sleep 1 eject -t sleep 1 done And this is said to be the same: watch -n 1 eject -T What does it do?What's the equivalent in batch? ...

Delphi ADO SQL Syntax Error

Hello. I am getting an Syntax Error when processing the following lines of code. Especially on the AQ_Query.Open; procedure THauptfenster.Button1Click(Sender: TObject); var option: TZahlerArray; begin option := werZahlte; AQ_Query.Close; AQ_Query.SQL.Clear; AQ_Query.SQL.Add('USE wgwgwg;'); AQ_Query.SQL.Add('INSERT INT...

unexpected T_TRY, expecting T_FUNCTION error message, not sure why ?

I am getting unexpected T_TRY, expecting T_FUNCTION error message and am not sure as too why am getting that, can't we use try and catch block inside class like this: class Processor { protected $dao; protected $fin; try { public function __construct($file) { //Open File for parsing. ...

How to shorthand array declaration in a method call?

Hi all, This is hopefully a softball syntax question: I need to call a method with an empty Object array for evaluation and set initial state. In C# I would just do this: func(new Object[]{}); In VB.NET I am forced to do this: Dim ctrls() As Control = {} func(ctrls) Is there a way to shorthand the call in VB.NET and have everythi...

Is the syntax written in descrition is correct for MySQL Triggers? will it work?

Is the syntax written in descrition is correct for MySQL Triggers? will it work? CREATE OR REPLACE TRIGGER myTableAuditTrigger 2 AFTER INSERT OR DELETE OR UPDATE ON myTable 3 FOR EACH ROW 4 BEGIN 5 IF INSERTING THEN 6 INSERT INTO myTableAudit (id, Operation, NewName, NewPhone) 7 VALUES (1, 'Insert ', :NEW.N...

In Ruby, What structures can a `rescue` statement be nested in

In ruby to catch an error one uses the rescue statement. generally this statement occurs between begin and end. One can also use a rescue statement as part of a block (do ... end) or a method (def ... end). My question is what other structures (loop, while, if, ...) if any will rescue nest within? ...

Is it possible to programatically catch JavaScript SyntaxErrors?

I don't think that this is doable, but wanted to throw it out to the community to confirm my suspicions. Let's say you're writing a program in another language like Python, PHP, or ASP. This program is intended to build another program written in JavaScript. However, the first program is unfortunately not immune to errors. So, occ...

C++ syntax of constructors " 'Object1 a (1, Object1(2))''

Hello I have a such syntax in program /* The Object1 is allowed to be changed */ class Object1 : BaseClass { BaseClass *link; int i; public: Object1(int a){i=a;} Object1(int a, Object1 /*place1*/ o) {i=a; link= &o;} }; int main(){ /* The initialization syntax must be preserved. No any new(), no other local objects...

How many different ways are there to get variable value in bash?

I found these two: [root@~]# echo $i; 2 [root@~]# echo ${i}; 2 ...

When to use or not use symbols in PHP

I'm reading a PHP book where the author says that symbols should be avoided except when it's valid to use them. Very informative stuff, if he could only elaborate or give code examples but he doesn't. Can someone from the experienced PHP bunch give me an example of what these symbols are, and when it makes sense to use them or not. I'm ...

Why does Perl's shift complain 'Type of arg 1 to shift must be array (not grep iterator).'?

I've got a data structure that is a hash that contains an array of hashes. I'd like to reach in there and pull out the first hash that matches a value I'm looking for. I tried this: my $result = shift grep {$_->{name} eq 'foo'} @{$hash_ref->{list}}; But that gives me this error: Type of arg 1 to shift must be array (not grep itera...

Way to call super(MyClass, self).__init__() without MyClass?

I find this syntax astoundingly annoying. Every time I rename my class, I have to change this call for no apparent reason. Isn't there some __class__ magic variable or something I can use at least? Interested in answers for Python 2.5, but it doesn't hurt to know if later versions fixed this. ...

How to change the value of None in Python?

I'm currently reading chapter 5.8 of Dive Into Python and Mark Pilgrim says: There are no constants in Python. Everything can be changed if you try hard enough. This fits with one of the core principles of Python: bad behavior should be discouraged but not banned. If you really want to change the value of None, you can do it, but don...

Copy **kwargs to self?

Given class ValidationRule: def __init__(self, **kwargs): # code here Is there a way that I can define __init__ such that if I were to initialize the class with something like ValidationRule(other='email') then self.other would be "added" to class without having to explicitly name every possible kwarg? ...