>The argument being that it is faster to use the X x(2) form because then only the
>constructor is called and with X x = 2 the constructor is called and then the copy constructor.
Ha! Unless the constructor is declared as explicit (in which case the second form is illegal), the two are identical. You can write a test program to strengthen your case:
Code:
#include <iostream>
class X {
public:
X(int) { std::cout<<"Default\n"; }
X(const X&) { std::cout<<"Copy\n"; }
};
int main()
{
X a = 1;
X b(1);
}
>Anyone knows where to find this or am I wrong in thinking that the forms dont differ?
The specific clauses can be found in section 12.3.1: Conversion by constructor. Specifically this one:
Code:
A constructor declared without the function-specifier explicit that can be called with a
single parameter specifies a conversion from the type of its first parameter to the type
of its class. Such a constructor is called a converting constructor. [ Example:
class X {
// ...
public:
X(int);
X(const char*, int =0);
};
void f(X arg)
{
X a = 1; // a = X(1)
X b = "Jessie"; // b = X("Jessie",0)
a = 2; // a = X(2)
f(3); // f(X(3))
}
—end example ]