반응형
''const pointer의 member function 호출은 const 형만 가능하다'
class ConstTest { private: int a; public: ConstTest() { a = 10; } public: int get_const() const { return a; } /// 함수 선언과 정의 모두에 const가 필요함. int get() { return a; } }; void test( const ConstTest* pConst, ConstTest* pNonConst ) { int ret1 = pConst->get_const(); /// OK int ret2 = pConst->get(); /// COMPILE ERROR int ret3 = pNonConst->get_const(); /// OK int ret4 = pNonConst->get(); /// OK } int main(int argc, _TCHAR* argv[]) { ConstTest ct1, ct2; test( &ct1, &ct2 ); return 0; }
반응형
'C, C++' 카테고리의 다른 글
tzset() locks in Linux after fork() (0) | 2011.07.12 |
---|---|
QtConcurrent : MapReduce 모델에 대한 Qt의 대안 (0) | 2011.01.08 |
c++ std exception example (0) | 2010.05.04 |
[CodeBlocks & wxPack] 손쉽게 Windows에서 wxWidgets(wxWindows) 개발 환경 구성하기 (3) | 2009.10.30 |
Google Protocol Buffers 활용기 - (1) (0) | 2009.07.09 |