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? 2 1336 do*****@gmail.com 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
On 21 Jan 2006 07:28:12 -0800, do*****@gmail.com 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Rasmus Fogh |
last post by:
Someone raised the question of automatic code generation a few weeks back.
And yes, we (CCPN) are using automatic Python code generation in a major
way. Basically we are making data models in...
|
by: Steven T. Hatton |
last post by:
This is from the draft of the previous version of the Standard:
http://www.kuzbass.ru:8086/docs/isocpp/expr.html
2- A literal is a primary expression. Its type depends on its form...
|
by: Michael Ovetsky |
last post by:
Consider:
int g(){int b=1; return b;}
int main()
{
int d=2;
g()=d;
}
|
by: Romeo Colacitti |
last post by:
Hi,
Does anyone here have a strong understanding for the meanings of the
terms "lvalue" and "rvalue" as it pertains to C, objects, and different
contexts? If so please share.
I've been...
|
by: tkrogc |
last post by:
I compiled the source below using the comeau compiler
http://www.comeaucomputing.com/tryitout/
Why does the f funtion compile while the g function produces an lvalue
error ?
(I thought the two...
|
by: puzzlecracker |
last post by:
From my understanding, if you declare any sort of constructors,
(excluding copy ctor), the default will not be included by default. Is
this correct?
class Foo{
public:
Foo(int); // no...
|
by: usao |
last post by:
Does anyone have an example of how to create a class which describes
and array, such that I can use the subscript operator on both the
left and right side of an assignment statement? This is as...
|
by: Chad |
last post by:
The following question actually stems from an old Chris Torek post.
And I quote from the following old CLC url
...
|
by: markryde |
last post by:
Hello,
Followed here is a simplified code example of something which I
try to implement; in essence , I want to assign a value to a return
value of a method is C. I know, of course, that in this...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |