C는 두 객체가 서로 같은걸 알아내는 함수/오퍼레이터가 어디있죠?
조회수 1004회
1 답변
-
C에서는 그런 기능이 없기 때문에 멤버끼리 비교하는 함수를 프로그래머가 직접 만들어야 합니다
#include <stdio.h> #include <stdbool.h> struct Coord{ int x, y; }; bool CoordEqual(struct Coord const c1, struct Coord const c2){ return (c1.x==c2.x && c1.y==c2.y); } int main(int argc, const char * argv[]) { struct Coord c1 = {3,5}; struct Coord c2 = {3,5}; struct Coord c3 = {5,3}; printf("c1 == c2: %s\n", CoordEqual(c1,c2) ? "true" : "false"); printf("c1 == c3: %s\n", CoordEqual(c1,c3) ? "true" : "false"); }
댓글 입력