Click here to Skip to main content
15,894,907 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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

QuestionTrimRight() and TrimLeft() for unicode characters. Pin
Rakesh529-Jul-09 3:40
Rakesh529-Jul-09 3:40 
AnswerRe: TrimRight() and TrimLeft() for unicode characters. Pin
Emilio Garavaglia30-Jul-09 1:42
Emilio Garavaglia30-Jul-09 1:42 
QuestionFont Pin
kumar sanghvi29-Jul-09 3:28
kumar sanghvi29-Jul-09 3:28 
QuestionRe: Font Pin
David Crow29-Jul-09 3:55
David Crow29-Jul-09 3:55 
AnswerRe: Font Pin
CPallini29-Jul-09 3:57
mveCPallini29-Jul-09 3:57 
GeneralRe: Font Pin
kumar sanghvi29-Jul-09 4:05
kumar sanghvi29-Jul-09 4:05 
GeneralRe: Font Pin
CPallini29-Jul-09 4:32
mveCPallini29-Jul-09 4:32 
GeneralRe: Font Pin
kumar sanghvi29-Jul-09 18:42
kumar sanghvi29-Jul-09 18:42 
GeneralRe: Font Pin
CPallini29-Jul-09 22:33
mveCPallini29-Jul-09 22:33 
QuestionResizing animations/images Pin
m_1729-Jul-09 2:44
m_1729-Jul-09 2:44 
AnswerRe: Resizing animations/images Pin
Maximilien29-Jul-09 2:57
Maximilien29-Jul-09 2:57 
GeneralRe: Resizing animations/images Pin
m_1729-Jul-09 3:12
m_1729-Jul-09 3:12 
AnswerRe: Resizing animations/images [modified] Pin
Adam Roderick J29-Jul-09 3:11
Adam Roderick J29-Jul-09 3:11 
GeneralRe: Resizing animations/images Pin
m_1729-Jul-09 18:50
m_1729-Jul-09 18:50 
QuestionHow do I get the correct font height in Hindi fonts? Pin
Gywox29-Jul-09 2:11
Gywox29-Jul-09 2:11 
AnswerRe: How do I get the correct font height in Hindi fonts? [modified] Pin
Adam Roderick J29-Jul-09 2:27
Adam Roderick J29-Jul-09 2:27 
AnswerRe: How do I get the correct font height in Hindi fonts? Pin
Iain Clarke, Warrior Programmer29-Jul-09 2:54
Iain Clarke, Warrior Programmer29-Jul-09 2:54 

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.