Last active
August 29, 2015 14:13
-
-
Save sumnjc/7293477c5a51392ad740 to your computer and use it in GitHub Desktop.
const - 함수선언
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class DummyClass{ | |
private: | |
int a; | |
public: | |
DummyClass(int _a):a(_a){ | |
} | |
void PrintMember() const{ | |
a++; // error: increment of member ‘DummyClass::a’ in read-only object | |
cout << a << endl; | |
} | |
}; | |
int main(){ | |
DummyClass dummy(4); | |
dummy.PrintMember(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
함수의 선언시에 const 를 사용하면 const 로 선언된 함수내에서는 멤버변수의 변경이 불가하다.