C++ 포인터 복사

당근한박스·2024년 4월 19일
0

C++

목록 보기
21/23

CTestDlg에서 부모 대화 상자의 포인터를 저장하고, 다른 대화 상자를 생성할 때 이 부모 대화 상자의 포인터를 전달할 수 있음

TestDlg

void TestDlg::testExam()
{
	CheckDlg dlg;
	dlg.SetParent(this);
	dlg.DoModal();
}

CheckDlg

// CheckDlg.h
const CWnd* m_pParentDlg;
// CheckDlg.cpp
void CheckDlg::SetParent(const CWnd* pWnd)
{
	m_pParentDlg = pWnd;
}


void CheckDlg::checkExam()
{
	TestDlg* pParent = NULL;
	if (m_pParentDlg != NULL) {
		(void)memcpy(&pParent, &m_pParentDlg, sizeof(TestDlg*)); // m_pParentDlg 값을 pParent에 복사
	}

}

1개의 댓글

comment-user-thumbnail
2024년 7월 1일

잘 보고 갑니다람쥐

답글 달기