Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C++ Programming

Copy construction with inaccessible base class copy c-tor


Hello,

Take a look at this program:
-----------------------------------
class B
{
     B(const B&);
     B& operator=(const B&);
public:
     B(int);

};

class C : public B
{
public:
     C(int);

};

int main()
{
     C c = C(42); // Comeau: no error
     B b = B(42); // Comeau: error

}

-----------------------------------
Both 'c' and 'b' are copy-constructed, as I understand it.
B's copy c-tor is inaccessible, so construction of 'b' is
ill-formed.  And Comeau (online test drive) flags it such.
But it lets the construction of 'c' through.  Should it?

As I understand it, a temporary can be omitted, but its
creation should be possible (12.2/1) as if it weren't omitted.
And since C's copy c-tor cannot be created (12.8/7), the code
that requires (or would require) it is also ill-formed.
Where do I err?  Or do I?

Thanks!

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

Hello,

On Feb 26, 9:35 pm, "Victor Bazarov" <v.Abaza@comAcast.net> wrote:

If everything were right the copy constructor would be called.

> B's copy c-tor is inaccessible, so construction of 'b' is
> ill-formed.  And Comeau (online test drive) flags it such.

yes. b cannot be copy constructed.

> But it lets the construction of 'c' through.  Should it?

NO. c cannot be copy constructed as well. Compiler shall not generate
a copy constructor as the base class copy constructor is private.
SO this is an error too.

> As I understand it, a temporary can be omitted, but its
> creation should be possible (12.2/1) as if it weren't omitted.
> And since C's copy c-tor cannot be created (12.8/7), the code
> that requires (or would require) it is also ill-formed.
> Where do I err?  Or do I?

> Thanks!

> V
> --
> Please remove capital 'A's when replying by e-mail
> I do not respond to top-posted replies, please don't ask

--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

Sounds logical.  gcc rejects both lines, Sun CC only barfs on C c = C(42);

--
Ian Collins.

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc