koger
asked on
const pass by reference
Hi
how is it possible to pass a paramter to a function as a const reference.
In C it would look something like this
void Proc(const int &i)
{}
Please don't tell me this is one of the rare cases where C is outrunning Delphi
how is it possible to pass a paramter to a function as a const reference.
In C it would look something like this
void Proc(const int &i)
{}
Please don't tell me this is one of the rare cases where C is outrunning Delphi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The const reserved word in method parameters means the compiler should not create a local copy of the parameter, coz the parameter won't be modified.
If you wanna pass stuff by reference, i.e pointing to the
actual variable you'd use the var specifier.
eg.
procedure Proc(var I: Integer);
Although there's no real gain here coz you're still
passing 32 bits.
If you wanna pass stuff by reference, i.e pointing to the
actual variable you'd use the var specifier.
eg.
procedure Proc(var I: Integer);
Although there's no real gain here coz you're still
passing 32 bits.
for instance you can have :
procedure Proc(const I: Integer);
or
procedure DoStuff(const List: TList);
you can do anything with List except assign another value to it
so you can do:
List.Capacity:=x;
but you can't do:
List:=TList.Create;
or
List:=SomeOtherList;