我想将类型B的对象分配给类型A的对象,但我不知道为什么它可以在不同类型的任务中工作?为什么它在我将对象分配给其他对象时起作用?
#include <stdio.h>
class B
{
public:
B()
{
printf("B default constructor.\n");
}
};
class A
{
public:
A()
{
printf("A Default constructor.\n");
}
A(B const& b) // if add the tag "explicit" for the constructor, it will not work...
{
printf("User constructor.\n");
}
A(const A& a)
{
printf("copy-constructor.\n");
}
void get(){printf("A::get\n");}
};
int main()
{
A a = B(); // What's the meaning to assign object of type B to object of type A?
为什么它可以在上面行? 这样做是如何工作的?
a.get();
}