Umm, am I missing something here?
// Forward declaration of getData
void getData(int& lengCo,int& lengGro,string& comet,string& group);
The & in this function prototype means the function accepts a reference
(changes affect the actual variable, not a copy) for those variables. So
void ChangeSpeed(int& Speed)
{
Speed = 7;
}
// In main()
int Speed = 0;
// Call ChangeSpeed
ChangeSpeed(Speed);
// Speed is now 7
If I had done
void ChangeSpeed(int Speed)
{
Speed = 7;
}
// In main()
int Speed = 0;
// Call ChangeSpeed
ChangeSpeed(Speed);
// Speed is still 0 because we only changed a copy
The * means a pointer. So
void ChangeSpeed(int* Speed)
{
// 'dereference' the pointer - act on what it is pointing to
*Speed = 7;
}
// In main()
int MySpeed = 0;
// Pointer points to MySpeed - in this case & means the address of
int* Speed = &MySpeed;
// Call ChangeSpeed
ChangeSpeed(Speed);
// MySpeed is now 7
Apologies if I have got the wrong end of the stick,
Daniel
>From: Jeeun Cho <koo...@ya...>
>To: dev c <dev...@li...>
>Subject: [Dev-C++] & and *
>Date: Tue, 25 Feb 2003 23:03:16 -0800 (PST)
>
>void
>getData(int&lengCo,int&lengGro,string&comet,string&group);
>void Convert(int lengCo,int lengGro,string
>comet,string
>group,vector<int>&ComNum,vector<int>&GroNum);
>void
>modNum(int&modCom,int&modGro,vector<int>ComNum,vector<int>GroNum,int
>lengCo,int lengGro);
>
>this is part of my program...and..as u can see, i used
>& between a data type and a changeable variable..(i
>was taught lyke that in my c++ class at school)..
>but i found out that people are using * instead of &
>for changeable variables...
>so..i chaged every & to * and compiled it, but i got
>lotta errors; when i used & and compiled, i didnt get
>any error..
>
>what should i use or do?
>
>__________________________________________________
>Do you Yahoo!?
>Yahoo! Tax Center - forms, calculators, tips, more
>http://taxes.yahoo.com/
>
>
>-------------------------------------------------------
>This SF.net email is sponsored by: Scholarships for Techies!
>Can't afford IT training? All 2003 ictp students receive scholarships.
>Get hands-on training in Microsoft, Cisco, Sun, Linux/UNIX, and more.
>www.ictp.com/training/sourceforge.asp
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
_________________________________________________________________
MSN Messenger - fast, easy and FREE! http://messenger.msn.co.uk
|