Quote Originally Posted by joncaves View Post
There is one change that fell out of the implementaion of rvalue references that has broken some code bases internally. It is code like the following:

Code:
struct S
{
    S();
    explicit S(const S&);
};
 
void f(S);
 
int main()
{
    S s;
 
    f(s);
}
This code compiles with Visual C++ 2008 SP1 (and with previous compilers) but it is, correctly, rejected by Dev10. If you make the default copy-constructor of a class 'explicit' you are saying that you can't pass an instance of the class to a function. The "fix" in every case we have seen so far is to remove the 'explicit' keyword from the default copy-constructor - it was usually added as a result of over enthusiasm.
Learnt something new. I never understood why people make copy constructors explicit because as far as I knew it only prevented assignment-looking calls to the copy constructor.

ie.

classname a;
classname b(a); // is ok if copy constructor is explicit
classname c = a; // fails if classname has explicit copy constructor.

I suppose thinking about it passing by value would be an implicit call and not an explicit call.

Is there ever a good reason to make copy constructors explicit?
Personally i have only used explicit constructors for single argument or multiargument constructors where all but one argument has a default value.

While talking about explicit, is it so hard to implement explicit conversion operators which is something I felt c++ needed for years?