clause 20: Prefer to replace pass-by-value with Pass-by-reference-to-const
By default, C + + passes objects to (or from) functions in by value, a way that inherits from C. Unless you specify otherwise, the function arguments are based on the actual argument's complex, and the caller gets a duplicate of the function return value. The creation of a duplicate (copy) takes time and wastes resources, as shown i
When you write C # before, the pass-through parameter is used by the object.
Now to PHP, found that most of the people are using an array of parameters, the array will cause later to see the code does not know what values are stored in the array.
Daniel, do you use arrays to pass parameters or to pass parameters with objects?
Reply content:
When you write C
Remember the truth: JS function Pass parameters, whether it is a simple data type, or reference data type, is the value of the pass!!Here is an example of the JS Red envelope book:
function setName(obj) {
obj.name = "Nicholas";
obj = new Object();
obj.name = "Greg";
}
var person = new Object();
setName(person);
alert(person.name); // "Nicholas"
Some people will ask
The day before yesterday when the system was in the Java parameter Transfer problem card, looking back to the relevant information, the parameter transfer problem has a new understanding and mastery, but there is a problem is still very vague, is Java in the end whether there is only value transmission, because in the data access, Often see some people say Java only value is passed, but some people say that the value of the pass, but also a reference
Page pass-through is a problem that will be faced in the early days of the study, such as page pass value, store object value, Ajax, class, model, form, etc. But generally speaking, it is simpler to use Querystring,session,cookies,application,server.transfer. In the interview, often encounter such problems, in fact, we will be more familiar with several of these methods, because the project is often used.
The transfer of parameters can be divided into two types of transmission value and address, what is the difference?
12345678910
function fun($num1,$num2){$num1=100;$num2=1000;}$n1=1;$n2=10;fun($n1,$n2);echo “n1={$n1} n2={$n2}”;?>
The result is: N1=1 n2=10
This section of code is the process of passing values, custom function fun parameters pass specific $n1, $n 2 value, this is easy to understand, I said
is no relationship with the storage unit that Num points to, and of course it does not change the value in this storage unit.
Therefore, the value is passed, passing the contents of the storage unit (8 basic types: value, non-basic type: The address of the actual object).2. What is reference deliveryonly values are passed in Java, and no reference is passed. The so-called reference pass is just a faulty concept.For example:Class Person { Public
One, the middle pass valueGlobal variables1. Store the median value (delegate--is more troublesome)@property (Nonatomic,strong) NSString *labeltext;2. Save the value (put in the Application object)Yyappdelegate *appdelegate = [UIApplication sharedapplication].delegate;Appdelegate.labeltext = Label.text;3. Fetching dataYyappdelegate *appdelegate = [UIApplication sharedapplication].delegate;Label.text =appdelegate.labeltext;Second, forward valueA->bLoca
A detailed description of value passing and reference passing:1: what is passed by valueRefers to when a method call passes a parameter that is passed by a copy of the Value. Examples are as Follows:[java]View PlainCopy
Public class Temptest {
Private void test1 (int A) {
Do Something.
}
Public static void main (string[] Args) {
Temptest t = new Temptest ();
int a = 3;
T.test1 (a); //the parameter A passed here is passed by value
}
}
Passing
Read a post on the internet to explain the value of Java and pass by reference, feel quite comprehensive, turn around, for later study reference:1: What is passed by valueRefers to when a method call passes a parameter that is passed by a copy of the value. Examples are as follows:public class Temptest {private void test1 (int a) { //do something} public static void Main (string[] args) {tempt EST T = new temptest (); int a = 3; T.test1 (a); //T
Key points:
Try to replace pass-by-reference-to-const with pass-by-value. This is usually more efficient and avoids the problem of object cutting when the subclass object is copied to the base class.
Pass-by-value should be used for the internal value type, STL iterator, and function object.
By default, c ++ uses the by value Method to
Parse Java to pass by value or by reference, parse java to pass reference
1: What is passed by value?
It indicates that when a method is called, The transmitted parameters are copied and transmitted by value. Example:
Public class TempTest {private void test1 (int a) {// do something} public static void main (String [] args) {TempTest t = new TempTest (); int a = 3; t. test1 (a); // The parameter a passed h
Android development by default, the bundle bundle=new bundle (); The pass-through value cannot be passed directly to the map object, but the workaround:The first step: encapsulate your own map to enable serialization?
12345678910111213141516
/*** 序列化map供Bundle传递map使用* Created on 13-12-9.*/public class SerializableMap implements Serializable { private Mappublic Mapreturn map;}public void setMap(Mapthis.map = map;}}
Step Two:
) {P.setproname ("After"); P.setnum (1); }} classProduct {Private intnum; PrivateString Proname; Public intGetnum () {returnnum; } Public voidSetnum (intnum) { This. num =num; } PublicString Getproname () {returnProname; } Public voidsetproname (String proname) { This. Proname =Proname; }}The result of the operation is: p.proName=after and p.num=1 .The two examples above are obvious value passing and reference passing. But what if the argument is of type string? Let's tak
PHPSSO cannot communicate in phpcmsv9 (PHPSSO cannot communicate indirectly affects phpcmsv9 registrants cannot pass "duplicate names cannot pass"). In general, most people do this: make a local virtual environment and use localhost or 127.0.0.1 to install the V9 system. there is no problem with local communication, so we will make a local data backup, at that time, during remote installation, domain names
Simple pass game (matrix) and pass game MatrixSimple pass gameTime Limit:1000 msMemory Limit:65536KB 64-bit integer IO format:% LldJava class name:Main
K (3 Input
The first line is an integer T (T
In the next T row, enter two numbers N and K (3 Output
Output T rows. Each row outputs N groups. K corresponds to the result of the 10 ^ 9 + 7 solution.Sample Input
23
Java is a value pass :(1) when the basic type is passed as a parameter, it is a copy of the transfer value, no matter how you change the copy, the original value will not change;(2) When a reference to an object is passed as a parameter, a copy of the object's address in memory is passed to the parameter, and the original value is unchanged regardless of how the address value is changed. Reference: http://blog.sina.com.cn/s/blog_4b622a8e0100c1bo.htm
Use the echart pie chart to pass the time ., Echart pie pass time
The new company has just been idle for a few days. The leaders asked me to do some irrelevant work and optimize the report statistics !!! Previously, flash was used. Now we need to change it to echart. Well, I have never used it before. I studied it with my learning attitude. Writing something to pass
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.