나는 다음과 같은 한 클래스 :정의 명시 적 과부하 생성자 문제
class CLASS1
{
CLASS1();
CLASS1(const CLASS1 &obj);
CLASS1 operator +(const CLASS1 &obj) {
CLASS1 srcObj;
// doing add stuff here
return srcObj;
}
void func()
{
CLASS1 boj = // some method which returns CLASS1 obj.
}
CLASS1& operator =(const CLASS1 &obj) {
// copy properties
}
}
확인이 잘 작동합니다. 그러나 잠시 후 암시 적 변환을 피하기 위해 클래스를 명시 적으로 만들기로 결정했습니다. 내가 명시 적으로 할당을 오버로드했습니다에도 불구하고,
class CLASS1
{
explicit CLASS1();
explicit CLASS1(const CLASS1 &obj);
CLASS1 operator +(const CLASS1 &obj) {
CLASS1 srcObj;
// doing add stuff here
return srcObj; // compiler gives non-matching errors
}
void func() {
CLASS1 boj = somemethods(); // compiler gives non-matching errors
}
CLASS1& operator =(const CLASS1 &obj) {
// copy properties
}
}
지금, 컴파일러는 제공하지 않습니다 '호출 할 일치하는 기능을 ...'오류 (위의 코드에 지정된) : 따라서, 나는 이런 식으로했습니다 운영자. 내 실수는 어디 갔지?