這是指針到實現代碼一個最小化的部分:克++ 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>&'
但是它可以通過小黑客來修復。如果我通過'& *此'而不是'此',那麼它會帶來可編譯狀態。
是G ++迴歸還是新的C++標準功能,它消除了向後兼容性?
它編譯在gcc-4.3.2上:http://ideone.com/nKcI6m – slonma 2015-02-06 07:08:28