c,c++/c++ 관련 개념 및 문법
explicit 키워드, mutable 키워드
YoonJongSeok
2023. 7. 11. 14:49
c++ - C++의 explicit 키워드는 뭘 하는 건가요? | 프로그래머스 커뮤니티 (programmers.co.kr)
C++의 explicit 키워드는 뭘 하는 건가요?
제가 인터넷을 돌아다니다가 어떤 답변에서 밑에 C++ 코드를 봤는데 이 explicit은 무슨 일을 해주는 건가요? 소스코드 class String { public: explicit String (int n); //allocate n bytes String(const char *p); // initializ
qna.programmers.co.kr
형변환을 모두 명시적으로 해주도록 하는 것이다.
mutable 키워드
const 함수는 멤버변수의 값들을 바꿀 수 없다고 배웠는데, 멤버변수를 mutable로 선언하였다면 const 함수에서도 바꿀 수 있다.
class A {
mutable int m_data;
public:
A(int data) : m_data(data) {}
void changeData(int data) const
{ m_data = data; }
};