Re: VS2005 - question about copy-ctor
- From: "Patrick Kowalzick" <patrick.kowalzick@xxxxxxxxxxxxxx>
- Date: Fri, 24 Mar 2006 12:51:48 +0100
Hello Tom,
I agree that it shouldn't compile, and for 2 separate reasons:
1: A's default constructor cannot access the default constructor for the
member copy_protection - remember that protected access only gives you
access to protected members of bases through pointers, references and
objects of the derived class, not the base class (this is to prevent one
derived class from breaking objects of other derived classes derived from
the same base). As a result, A doesn't have a well-formed default
constructor, so even "A a;" shouldn't compile. This is covered in 11.5/1
of the standard.
Delete the member copy_protection to get around this, and try a different
compiler to get the error in the first place.
Normally, I do not use a member copy_protection. It was just to test VS2005
:).
2: In the call, "c" is copy initialized from a default constructed A. The
compiler is allowed to optimize out the copy, but according to the
standard it must check that the copy could be made (e.g. that there is an
accessible copy constructor). This is covered in 12.2/1 of the standard.
Again, use a different compiler to get the error.
VS2005 is the first, where I do not get the error. I was a little bit
surprised, as this is quite basic stuff. But perhaps MS will launch a 8.1
soon :). 8.0 is a little bit annoying sometimes.
class A : public noncopyable // inherit to avoid copying
{
noncopyable copy_protection; // make member to avoid copying
};
Should be:
class A : noncopyable // no need for public inheritance
{
};
True.
You may want to report the bugs to MS.
Yes, I want. There is antoherone I want to report, but I do not know how. I
googled a little bit, but was not successful, yet.
Regards,
Patrick
.
- Follow-Ups:
- Re: VS2005 - question about copy-ctor
- From: Bruno van Dooren
- Re: VS2005 - question about copy-ctor
- References:
- VS2005 - question about copy-ctor
- From: Patrick Kowalzick
- Re: VS2005 - question about copy-ctor
- From: Tom Widmer [VC++ MVP]
- VS2005 - question about copy-ctor
- Prev by Date: Re: problem using MFC in clr
- Next by Date: Why do I get these kind of warnings when building my exefile
- Previous by thread: Re: VS2005 - question about copy-ctor
- Next by thread: Re: VS2005 - question about copy-ctor
- Index(es):
Relevant Pages
|