I want to reproduce a get style function from C++ in a C program. In C++, there can be two functions in a class for assigning the value and setting the value. Is there any equivalent way in `C? Lets say i have following structure:
typedef struct test_help
{
int a;
void** numArrays;
struct test_help *next;
} help_node, *help;
I have function like the following for accessing the value of structure:
int access_int(help damaru) {
return damaru->a;
}
so I can assign the value of integer from the structure:
int y = access_int(damaru);
But i want to assign the value to the memeber of structure like:
help damaru;
int z=10;
damaru->int = z;
I would like to get rid of the use of ->. I would like to write a function which is similar to the assign function. I would like to remind you that use of access function in left hand side shows warnings.
You have a typo that is why you get a syntax error, the correct way to do this is
To make an access function something like this would work
Then use
Remember you are using C. C is not object oriented so there is no direct mapping of this object oriented feature.