DataViewCtrlBase::GetModel()
는 비 const
restrict로하고 const
restrict로 과부하를 모두 갖는다. 비 const
오버로드는 현재 클래스 인스턴스가 const
컨텍스트에서 액세스되는 경우에만 호출됩니다.
당신은이 (의사)과 같은 과부하 된 것으로 이러한 방법을 생각할 수 있습니다
DataViewModel* GetModel(DataViewCtrlBase* this) { /* ... */ } /* (0) */
const DataViewModel* GetModel(const DataViewCtrlBase* this) { /* ... */ } /* (1) */
예 :
DataViewCtrlBase x;
auto& x_non_const = x;
x_non_const.GetModel(); // Calls (0) | Equivalent to: GetModel(x_non_const)
const auto& x_const = x;
x_const.GetModel(); // Calls (1) | Equivalent to: GetModel(x_const)
어쩌면 둘 사이의 또 다른 차이가? – juanchopanza
함수 정의 뒤의'const'는 서명의 일부이므로 다른 함수입니다 – EdChum
표준 라이브러리는 이러한 오버로드로 가득차 있습니다. –