Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------------------MYSTRUCT.H---------------------------
- #ifndef _MYSTRUCT_H_
- #define _MYSTRUCT_H_
- typedef struct MyStruct {
- int myValue1;
- char myValue2;
- void (*setValue1)(struct MyStruct *myStruct, int myValue1);
- void (*setValue2)(struct MyStruct *myStruct, char myValue2);
- } MyStruct;
- struct MyStruct myStructConstructor();
- void setValue1(struct MyStruct *myStruct, int myValue1);
- void setValue2(struct MyStruct *myStruct, char myValue2);
- #endif
- --------------------------MYSTRUCT.C-------------------------
- #include "MyStruct.h"
- #include <stdio.h>
- struct MyStruct myStructConstructor() {
- MyStruct myStruct;
- myStruct.setValue1 = setValue1;
- myStruct.setValue2 = setValue2;
- }
- void setValue1(struct MyStruct *myStruct, int myValue1) {
- myStruct->myValue1 = myValue1;
- }
- void setValue2(struct MyStruct *myStruct, char myValue2) {
- myStruct->myValue2 = myValue2;
- }
- int main(void) {
- MyStruct str = myStructConstructor();
- str.setValue1(&str, 1);
- printf("%d\n", str.myValue1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement