| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"" |
| Date: |
21 Jan 2006 09:28:12 AM |
| Object: |
Automatic lvalue in functions |
I have a number of functions that return structs. Some sample calls:
mystruct = func_one(mystruct, var1, var2);
mystruct = func_two(mystruct, whatever, scale, thirdvar);
In every call, I'm passing the lvalue mystruct. I think it makes the
code repetitive and cluttered to have the lvalue listed as a parameter
on every function call.
I would rather have:
mystruct = func_one(var1, var2);
mystruct = func_two(whatever, scale, thirdvar);
Yet still be able to access the lvalue within the function. Is there a
way using the preprocessor or some other trick to accomplish this? If
it were the preprocessor, it could parse this line:
mystruct = func_one(var1, var2);
Find the value to the left of the = and insert it with a comma after
func_one(
Is there a way to do this?
.
|
|
| User: "TB" |
|
| Title: Re: Automatic lvalue in functions |
21 Jan 2006 09:34:46 AM |
|
|
sade:
I have a number of functions that return structs. Some sample calls:
mystruct = func_one(mystruct, var1, var2);
mystruct = func_two(mystruct, whatever, scale, thirdvar);
In every call, I'm passing the lvalue mystruct. I think it makes the
code repetitive and cluttered to have the lvalue listed as a parameter
on every function call.
I would rather have:
mystruct = func_one(var1, var2);
mystruct = func_two(whatever, scale, thirdvar);
Yet still be able to access the lvalue within the function. Is there a
way using the preprocessor or some other trick to accomplish this? If
it were the preprocessor, it could parse this line:
mystruct = func_one(var1, var2);
Find the value to the left of the = and insert it with a comma after
func_one(
Is there a way to do this?
What's stopping you from making them member functions?
--
TB @ SWEDEN
.
|
|
|
|
| User: "Zara" |
|
| Title: Re: Automatic lvalue in functions |
21 Jan 2006 10:32:28 AM |
|
|
On 21 Jan 2006 07:28:12 -0800, wrote:
I have a number of functions that return structs. Some sample calls:
mystruct = func_one(mystruct, var1, var2);
mystruct = func_two(mystruct, whatever, scale, thirdvar);
In every call, I'm passing the lvalue mystruct. I think it makes the
code repetitive and cluttered to have the lvalue listed as a parameter
on every function call.
I would rather have:
mystruct = func_one(var1, var2);
mystruct = func_two(whatever, scale, thirdvar);
Yet still be able to access the lvalue within the function. Is there a
way using the preprocessor or some other trick to accomplish this? If
it were the preprocessor, it could parse this line:
mystruct = func_one(var1, var2);
Find the value to the left of the = and insert it with a comma after
func_one(
Is there a way to do this?
Apart from making it a memeber function (as noted by TB), you may just
pass a non-const refrence to the struct:
void func_one (type_of_mystruct& mystruct, type1 var1, type2 var2);
You may the modify mystruct within func_one. But the syntax of calling
would be:
func_one(mystruct,var1,var2)
and not the one you desire.
*AND* it is much, much better, to make it a member function.
Zara
.
|
|
|
|

|
Related Articles |
|
|