이 구현 코드의 포인터를 최소화 부분이다그램 ++ 패스 기준에 4.9.2 회귀 '이'
template<typename T>
class PImpl {
private:
T* m;
public:
template<typename A1>
PImpl(A1& a1) : m(new T(a1)) {
}
};
struct A{
struct AImpl;
PImpl<AImpl> me;
A();
};
struct A::AImpl{
const A* ppub;
AImpl(const A* ppub)
:ppub(ppub){}
};
A::A():me(this){}
A a;
int main (int, char**){
return 0;
}
그것은 컴파일 가능한 G ++ 4.8 이전에서와 같이 잘 작동한다. 그러나 G ++ 4.9.2 컴파일러는 다음 오류를 발생시킵니다 :
prog.cpp: In constructor 'A::A()':
prog.cpp:24:15: error: no matching function for call to 'PImpl<A::AImpl>::PImpl(A*)'
A::A():me(this){}
^
prog.cpp:24:15: note: candidates are:
prog.cpp:9:5: note: PImpl<T>::PImpl(A1&) [with A1 = A*; T = A::AImpl]
> PImpl(A1& a1) : m(new T(a1)) {
^
prog.cpp:9:5: note: no known conversion for argument 1 from 'A*' to 'A*&'
prog.cpp:2:7: note: PImpl<A::AImpl>::PImpl(const PImpl<A::AImpl>&)
class PImpl {
^
prog.cpp:2:7: note: no known conversion for argument 1 from 'A*' to 'const PImpl<A::AImpl>&'
그러나 작은 해킹으로 고칠 수 있습니다. '이'대신 '& * this'을 전달하면 컴파일 가능한 상태가됩니다.
역 호환성을 제거하는 G ++ 회귀 또는 새로운 C++ 표준 기능입니까?
gcc-4.3.2에서 컴파일되었습니다. http://ideone.com/nKcI6m – slonma