암시 적으로 변환 개체와 기능 과부하 이동 호출 할 때 :컴파일 오류이 프로그램은 <code>clang++ test.cpp -std=c++0x</code>를 사용하여 컴파일되지 않습니다
class A
{
public:
A() {}
A(const A&) {}
A(A&&) {}
A& operator = (const A&) { return *this; }
A& operator = (A&&) { return *this; }
};
class B
{
A m_a;
public:
operator const A &() const
{
return m_a;
}
};
int main(int, char**)
{
A a;
B b;
a = b; // compile error
}
오류를 컴파일을 :
Apple clang version 3.0 (tags/Apple/clang-211.10.1) (based on LLVM 3.0svn)
test.cpp:25:9: error: no viable conversion from 'B' to 'A'
a = b;
^
test.cpp:5:5: note: candidate constructor not viable: no known conversion from 'B' to
'const A &' for 1st argument
A(const A&) {}
^
test.cpp:6:5: note: candidate constructor not viable: no known conversion from 'B' to 'A &&'
for 1st argument
A(A&&) {}
^
test.cpp:15:5: note: candidate function
operator const A &() const
^
test.cpp:8:23: note: passing argument to parameter here
A& operator = (A&&) { return *this; }
^
왜 컴파일되지 않습니다? 왜 컴파일러는 A::operator = (const A&)
보다 A::operator = (A&&)
을 선호합니까?
또한 A a; a = b;
(위의 프로그램)과 A a(b);
이 모두 컴파일되지 않는데 A a = b;
이 컴파일되는 이유는 무엇입니까?
어떤 버전의 Clang입니까? – ildjarn
FWIW, 코드가'clang version 3.0 (tags/RELEASE_30/final) 으로 컴파일됩니다. 대상 : x86_64-pc-linux-gnu 스레드 모델 : posix' 및 GCC 4.5.3 또는 4.6.2 정상인지 아닌지 전혀 알 수 없음) – Mat
clang 버그처럼 보입니다. –