explicit 키워드

Tags:

KLDP BBS :: 주제 보기 – char*과 string 간의 전환

명시적 형 변환

#include <iostream>

using namespace std;

class T {
public:
  explicit T(int a) {
  cout << a << endl;
}
};

void test(T t) {}

int main() {
   test(5); // 에러
   T a = 5; // 에러
   return 0;
}

explicit라고 쓰면 암시적 형 변환이 일어나지 못하는군요.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *