Notice
Recent Posts
Recent Comments
Today
Total
05-08 00:08
Archives
관리 메뉴

Jeongchul Kim

C 언어에서 struct로 Java의 Class 묘사 본문

Computer Language

C 언어에서 struct로 Java의 Class 묘사

김 정출 2016. 2. 4. 15:48

C 언어에서 struct로 Java의 Class 묘사


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

#include <stdio.h>

#include <stdlib.h>

struct student {

   int num;

   double grade;

   int (*getNum)();

   void (*printStudent)();

};

int get_Num(struct student *obj) {

   return obj->num;

}

void print_Student(struct student *obj) {

   printf("학번 : %d, 학점 : %.1lf\n",obj->num,obj->grade);

}

int main(void) {

   struct student s1;

   s1.num = 2010;

   s1.grade = 3.8;

   s1.getNum = get_Num;

   s1.printStudent = print_Student;

   s1.printStudent(&s1);

   return EXIT_SUCCESS;

}




함수포인터를 이용하여 메소드 기능 구현

Comments