I'm reading about copy-constructors and the differences between copy initialization and direct initialization. I know that copy and direct initialization differ only for (user-defined) class types and that the first implies sometimes an implicit conversion (by a converting constructor).For example if I could initialize an object of class A:
class A {
public:
// default constructor
A() : a(1) {}
// converting constructor
A(int i) : a(i) {}
// copy constructor
A(const A &other) : a(other.a) {}
private:
int a;
};
int main()
{
// calls A::A(int)
A a(10);
// calls A::A(int) to construct a temporary A (if converting constructor is not explicit)
// and then calls A::A(const A&) (if no elision is performed)
A b=10;
// calls copy constructor A::A(const A&) to construct an A from a temporary A
A c=A();
// what does this line do?
A d(A());
}
I read that the last line does not create an A by direct initializing d from a temporary A() but it declares a function named d,which returns an A and takes an argument of function type ( a pointer to a function really ). So my question is, is it true? and if it's true, how can I perform direct initialization of an object from a temporary like:
type_1 name(type_2(args));
assuming that type_1
has a contructor that takes a parameter of type type_2
is it something that can not be done?