Re: VS2005 - question about copy-ctor

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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


.



Relevant Pages

  • Re: "this" and "base"
    ... compiler and the programming language. ... a private inherited field in a base class from a derived class is that the ... > because the member "is a private". ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: operator=
    ... Compiler will supply - unless the programmer decides to do it - the ... It isn't required in an assignment: ... You will find that the code within the copy constructor and assignment ... Aside from the inlined code [i.e. the member ...
    (alt.comp.lang.learn.c-cpp)
  • Re: explicit call to copy constructor and operator = needed
    ... >>Why cant the compiler do this on its own. ... if you let the compiler create that copy constructor ... > make sure you properly initialise all the base classes and members ... for the "gb" member in the copy c-tor's initialiser list, ...
    (comp.lang.cpp)
  • Re: "this" and "base"
    ... "What keeps you from accessing a Private member" is more of what you are ... It is both the Compiler and Runtime engine that keep you from ... member function in your derived class you could have a local variable called ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Initializer list issue
    ... Well, I guess I'll tentatively blame my compiler, since I ... sidestepped whatever problem there was by making the derived class ... member a pointer and calling new in the constructor. ...
    (comp.lang.cpp)