Skip to content

Instantly share code, notes, and snippets.

@sumnjc
Last active August 29, 2015 14:13
Show Gist options
  • Save sumnjc/7293477c5a51392ad740 to your computer and use it in GitHub Desktop.
Save sumnjc/7293477c5a51392ad740 to your computer and use it in GitHub Desktop.
const - 함수선언
#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;
}
@sumnjc
Copy link
Author

sumnjc commented Jan 14, 2015

void PrintMember() const

함수의 선언시에 const 를 사용하면 const 로 선언된 함수내에서는 멤버변수의 변경이 불가하다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment