So basically this code:
class A {
};
class B {
B (const B& b) {}
public:
B (){}
B (const A& a) {}
};
int main()
{
A a;
B b1(a); //OK
B b2 = a; //Error
}
only generates an error for B b2 = a
. And that error is
error: ‘B::B(const B&)’ is private
Why is it attempting to call the copy constructor in addition to the direct conversion constructor?
It's clear from the error message that a temporary B
is created which is then used for copy-construction, but why? Where is this in the standard?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…