This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++ constructors called as args


Matthias Oltmanns <Mathias dot Oltmanns dot Oltmanns at sysde dot eads dot 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 at pocketpurchase dot 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]


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]