C++ 에서 클래스 private 에서 선언한 struct를 main 함수에서 호출하고 싶습니다
조회수 547회
헤더파일에서 Student란 이름의 class를 선언하였고 private에 lecture라는 구조체를 선언한 상태입니다. cpp 파일을 하나 더 만든 다음 메인함수에서 private 부분에 있는 lecture 구조체를 만들어서 사용하고 싶은데 어떻게 해야 할지 감이 잘 잡히지 않습니다. 사이트 이용이 처음이라 미숙한 부분이 있으면 지적 감사히 받겠습니다.
-
(•́ ✖ •̀)
알 수 없는 사용자
1 답변
-
미숙한 답변이 도움이 되었으면 좋겠습니다.
main.cpp
#include <iostream> #include "head.h" //여기서 include했습니다. using namespace std; int main() { Student st; st.setInit(); st.coutLecture(); return 1; }
head.h
#pragma once class Student { private: struct { int x; int y; }lecture; public: void setInit() { this->lecture.x = 3; this->lecture.y = 6; } void coutLecture() { std::cout << this->lecture.x << "," << this->lecture.y << "\n"; } };
-
(•́ ✖ •̀)
알 수 없는 사용자
-
댓글 입력