C++ constructors called as args

LLeweLLyn Reese llewelly@lifesupport.shutdown.com
Mon Mar 3 13:00:00 GMT 2003


Matthias Oltmanns <Mathias.Oltmanns.Oltmanns@sysde.eads.net> writes:

> Hi,
> 
> 
> Am Mon, 2003-03-03 um 09.09 schrieb Michal Liptak:
> > could you post the whole code, because this compiles fine:
> > class A  {
> >         // forward decl
> > };
> > 
> > class B {
> >         public:
> // You see the difference? With the keyword "public" the constructors
>are *NOW* public

exactly.

> >         B( const A& a ) {}
> >         B( const B& b ) {}
> > };
> > 
> > class C {
> >         public:
> // same as above
> >         void F1( A a ) { F2(a); }
> >         void F2( B b ) {}
> > };
> > 
> > int main(void) {
> >         C c;
> >         A a;
> >         c.F1(a);
> >         return 0;
> > }
> > 
> > plus I don't see why you pass arguments to F1() and F2 by value.. is it intended?
> > 
> > m.
> > 
> > On Sun, 02 Mar 2003 23:56:33 -0800
> > Michael Hunley <mhunley@pocketpurchase.com> wrote:
> > 
> > >I have some simple class combinations that effectively look like:
[snip]
> > >
> > >class A;        // forward decl
> > >
> > >class B {
> > >         B( const A& a );
> > >         B( const B& b );
> > >};
> > >
> > >class C {
> > >         void F1( A a ) { F2(a); }

This call to F2 requires use of a private constructor to create a
    temporary. Because the constructor is private, this is an error.

> > >         void F2( B b );
> > >};
[snip]



More information about the Gcc-help mailing list