473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

about the reference fuction

Hi all,

I have a question here, could anyone tell me what the differences bw
those funtions:

DataType move(DataType a){return a}

DataType &move(DataType &a){return a}

thanks!
Jul 22 '05 #1
2 1001

"Daqian Yang" <05*****@acadiau.ca> wrote in message news:bv***********@poseidon.acadiau.ca...
Hi all,

I have a question here, could anyone tell me what the differences bw
those funtions:

DataType move(DataType a){return a}

DataType &move(DataType &a){return a}

The return value of the former is a copy of the value it is passed.
The return value of the latter is a reference to the same value.
Jul 22 '05 #2

"Daqian Yang" <05*****@acadiau.ca> wrote in message
news:bv***********@poseidon.acadiau.ca...
Hi all,

I have a question here, could anyone tell me what the differences bw
those funtions:

DataType move(DataType a){return a}

DataType &move(DataType &a){return a}


The argument: in the second example it gets passed by reference instead of
value. A new copy is not made when the function is called. If it changes
in the function, it will change for the caller too (unlike the first
example).

The return type: in the second example, the return value is passed by
reference instead of value. This one is much more tricky and error prone.
It's similar in theory to using a pointer. You are not giving thecaller an
automatically created object. You are giving them a reference to some
storage that better have been dynamically created, or already existed. Then
you have to think about who is responsible for this storage after the call.
If you don't understand what I'm talking about, then don't use it until
you've learned a lot more! :-)
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: orion30 | last post by:
I would like to know, if an allocated variable returning by a fuction is unallocated automatically ? If no how to proceed ? Best regards ...
19
by: JKop | last post by:
When I compile and run the following on my system: #include <iostream> static int hello = 78; int ReturnValue(void) {
1
by: Szaki | last post by:
I use a BulkLoad to import file.xml to my base MS Server 2000. To import this xml file I need schema file. Mayby you know how to do this file mechanicy f.g. mayby somebody have some script in .net...
4
by: tham | last post by:
HI can i box and unbox a reference so that i can achieve a 'pointer to pointer' effect. i want to pass a reference as a parameter to a function and then have the function change what the reference...
6
by: Adam Right | last post by:
Hi, I am developing a project which uses "Microsoft Word Interop". There may be a case in which the end-user may not have Microsoft Office or Office Interops. So i do not want to add a com...
3
by: mike | last post by:
i've already used static fuction to make website i wanna common module that's why i used static fuctions. may be it's more than 100 fuction ...is it ok?
8
by: hu | last post by:
hi, everybody! I'm testing the fuction of strtok(). The environment is WinXP, VC++6.0. Program is simple, but mistake is confusing. First, the below code can get right outcome:"ello world, hello...
4
by: ThuKhanh | last post by:
So far I just use the call-by-reference method but don't pay attention to that. But now there is a question : in this method , we pass pointers to the fuction , so, after the function call , the...
22
by: Ruben | last post by:
Why would a method that is defined to return a reference such as with the operator overload of , operator, href& operator(int index){ return _array; } not cause a type mismatch compiler...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.