Skip to main content
GameDev.net gamedev.net
🔒 Locked

a simple question(i think)

Started by Cramit_the_Frog Oct 25, 2000 at 1:11 PM 0 replies 200+ views
Original Post
Cramit_the_Frog
Cramit_the_Frog
How do you make a function that takes multiple objects from two or more struct''s and manipulates thare member data? The function will need to take a different object struct and a second different object from a new struct and manipulate one object''s member data baised on bolth''s member data... Like this: struct A{ int characteristic; int life; }; struct B{ int characteristic; }; void function(A Target, B TargetA){A.life = A.characteristic - B.characteristic;}; How do i make the function take two objects, one struct A and one struct B, that arnt named Target and TargetA but rather what ever objects i make from the struct''s like: //so i could call the function whith any object''s i make from //the struct... B Brick; A Pick; function(Pick, Brick); //or A Cat; B Dog; function(Cat, Dog); So how do you make a universal function that will take objects and manipulate thare struct baised on the name... And i shouldnt have to overload because im using the same two struct''s but just different objects... help if you can...? ahhhh... could allways smell a graveyard
ahhhh... could allways smell a graveyard
jt_845s
jt_845s
If your function definition is small, you can use macros:

//-----------------------------------
// Code
//-----------------------------------

#define FUNC(x,y) x.a = 10; y.a = 20;

typedef struct
{
int a;
int b;
int c;
} somestruct1_t;

typedef struct
{
int a;
int b;
int c;
} somestruct2_t;


int main(void)
{
somestruct1_t s1;
somestruct2_t s2;

FUNC(s1, s2);

return 0;
}

//----------------------------------------------
// End Code
//----------------------------------------------

Hope that helps.

#define ignite_software 1
[source]#define ignite_software 1[/source]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.