Click here to Skip to main content
15,916,702 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: LPTSTR concatenation Pin
akhanal29-Jul-09 11:18
akhanal29-Jul-09 11:18 
QuestionLIBC.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup Pin
stephen.hazel29-Jul-09 10:14
stephen.hazel29-Jul-09 10:14 
QuestionQuestion about Boost::Regex library Pin
msn9229-Jul-09 8:47
msn9229-Jul-09 8:47 
QuestionHow can I show my dialog on the TOP from other window dialog? Pin
THAQCD29-Jul-09 7:38
THAQCD29-Jul-09 7:38 
AnswerRe: How can I show my dialog on the TOP from other window dialog? Pin
Code-o-mat29-Jul-09 9:35
Code-o-mat29-Jul-09 9:35 
QuestionRe: How can I show my dialog on the TOP from other window dialog? Pin
David Crow29-Jul-09 9:45
David Crow29-Jul-09 9:45 
AnswerRe: How can I show my dialog on the TOP from other window dialog? Pin
THAQCD30-Jul-09 8:37
THAQCD30-Jul-09 8:37 
GeneralRe: How can I show my dialog on the TOP from other window dialog? Pin
David Crow1-Aug-09 16:56
David Crow1-Aug-09 16:56 
Question[MISC] - Operators - Meaning of operator & Pin
Thang29-Jul-09 6:59
Thang29-Jul-09 6:59 
AnswerRe: [MISC] - Operators - Meaning of operator & Pin
David Crow29-Jul-09 7:05
David Crow29-Jul-09 7:05 
AnswerRe: [MISC] - Operators - Meaning of operator & Pin
enhzflep29-Jul-09 8:27
enhzflep29-Jul-09 8:27 
GeneralRe: [MISC] - Operators - Meaning of operator & Pin
Maximilien29-Jul-09 9:48
Maximilien29-Jul-09 9:48 
GeneralRe: [MISC] - Operators - Meaning of operator & Pin
enhzflep29-Jul-09 10:00
enhzflep29-Jul-09 10:00 
GeneralRe: [MISC] - Operators - Meaning of operator & Pin
Thang30-Jul-09 6:10
Thang30-Jul-09 6:10 
QuestionSlider control on the status bar (where does WM_HSCROLL go?) Pin
BabakTaati29-Jul-09 5:46
BabakTaati29-Jul-09 5:46 
QuestionReading from and writing to the registry in windows Vista Pin
Sternocera29-Jul-09 5:00
Sternocera29-Jul-09 5:00 
QuestionRe: Reading from and writing to the registry in windows Vista Pin
David Crow29-Jul-09 5:47
David Crow29-Jul-09 5:47 
AnswerRe: Reading from and writing to the registry in windows Vista Pin
bob1697229-Jul-09 5:53
bob1697229-Jul-09 5:53 
GeneralRe: Reading from and writing to the registry in windows Vista Pin
Sternocera29-Jul-09 23:38
Sternocera29-Jul-09 23:38 
QuestionReferences Pin
EliottA29-Jul-09 4:13
EliottA29-Jul-09 4:13 
AnswerRe: References Pin
Chris Losinger29-Jul-09 4:28
professionalChris Losinger29-Jul-09 4:28 
GeneralRe: References Pin
EliottA29-Jul-09 4:35
EliottA29-Jul-09 4:35 
GeneralRe: References Pin
Chris Losinger29-Jul-09 4:40
professionalChris Losinger29-Jul-09 4:40 
GeneralRe: References Pin
Maximilien29-Jul-09 7:59
Maximilien29-Jul-09 7:59 
AnswerRe: References Pin
Rajesh R Subramanian29-Jul-09 4:50
professionalRajesh R Subramanian29-Jul-09 4:50 
Hello,


EliottA wrote:

& int x;
int & x;
int &x;


The first one is plainly illegal.

The second and third have no difference between them. Ideally, I would prefer the third one to avoid any confusion while declaring multiple variables in the same statement. But while you are declaring such a reference variable, you *must* initialize it properly by specifying which variable is it referring to. Unless which, you won't get it to compile.

If a function takes a parameter in by reference (as opposed to 'by value'), any changes made to the variable passed in will reflect on the original variable passed while making the function call (similar to pointers, but the syntax is much cleaner).

This might help you:
void FuncRef(int &n)
{
	n = 0;
}

void FuncNormal(int n)
{
	n = 4;
}

void _tmain(int argc, _TCHAR* argv[])
{
	int i = 10;
	int &Ref = i; //Ref now refers to the variable i. If you change the value of Ref, i will change as well (and vice versa).
        //int &Ref2; //This line, if enabled, won't compile. Because Ref2 is not initialised properly.
	cout<<Ref<<endl; //Will display 10. Because Ref is a reference to i.
	Ref = 2;
	cout<<i<<endl; //Will display 2. Because Ref was changed to 2, but Ref itself is referring to i.
	FuncRef(i);
	cout<<i<<endl; //Will display 0. Because the function takes the parameter as a reference and has modified it!
	FuncNormal(i);
	cout<<i<<endl; //Will still display 0. Because FuncNormal does not take the parameter as reference.
	
}



It is a crappy thing, but it's life -^ Carlo Pallini

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.