• 카테고리

    질문 & 답변
  • 세부 분야

    게임 프로그래밍

  • 해결 여부

    해결됨

46:35 friend 키워드

24.02.21 15:02 작성 조회수 148

0

안녕하세요, 이해가 잘 안 가는 부분이 있습니다.

46:35 쯤 friend 키워드를 사용해서 gettypehash 함수를 안쪽에 선언한다고 말씀 하셨습니다.

 

구조체는 기본적으로 전역이기 때문에

friend를 선언하면 구조체의 멤버 함수였던 gettypehash 함수가 구조체 변수에 접근이 가능하면서 전역으로 사용이 가능한 전역 함수가 된다고 이해하면 되는지 궁금합니다.

답변 1

답변을 작성해보세요.

0

네 강의에서 자주 문의주는 내용인데요, C++에서 friend 멤버 함수는 클래스의 함수로 취급되지 않고 전역으로 간주됩니다.

A friend function is a function that isn't a member of a class but has access to the class's private and protected members. Friend functions aren't considered class members; they're normal external functions that are given special access privileges. Friends aren't in the class's scope, and they aren't called using the member-selection operators
https://learn.microsoft.com/en-us/cpp/cpp/friend-cpp?view=msvc-170