Hi everyone,
I'm trying to learn plain old C; I'm reasonably proficient with C# but new to C. I'm trying to figure out whether there is a way to do a "calculated member" (for want of a better name) in a struct. For example, starting with the following:
I'd like to be able to add some sort of "int Area = Width * Height;". It'll obviously be more complicated than that, but is this sort of thing possible in C? I've created a function called Rectangle_Area that takes a Rectangle and returns an int, but I'm not sure whether there's a way to "link" it into the main struct. I don't yet know all the terms that I should be searching for so can someone please help a newbie out?
I'm trying to learn plain old C; I'm reasonably proficient with C# but new to C. I'm trying to figure out whether there is a way to do a "calculated member" (for want of a better name) in a struct. For example, starting with the following:
Code:
typedef struct {
int Width;
int Height;
} Rectangle;
I'd like to be able to add some sort of "int Area = Width * Height;". It'll obviously be more complicated than that, but is this sort of thing possible in C? I've created a function called Rectangle_Area that takes a Rectangle and returns an int, but I'm not sure whether there's a way to "link" it into the main struct. I don't yet know all the terms that I should be searching for so can someone please help a newbie out?
Last edited: