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


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
>         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 will post this to the news groups as well, if this is not the correct 
> >place to ask this question my humble apologies.
> >
> >I am working under RedHat Linux 8.0 which reports I am using GCC 3.2-7 
> >(which does not seem to match the GNU gcc versioning, but...).  I have 
> >3.2.2, but have not deployed yet.
> >
> >I am brand new to linux and gcc and am trying to port an app from Windows 
> >written in C++ using MSVC 6.
> >
> >I have some simple class combinations that effectively look like:
> >
> >class A;        // forward decl
> >
> >class B {
> >         B( const A& a );
> >         B( const B& b );
> >};
> >
> >class C {
> >         void F1( A a ) { F2(a); }
> >         void F2( B b );
> >};
> >
> >I get several errors from the above situation, apparently because g++ does 
> >not like calling the constructor to create a temp B from an A.  One of the 
> >messages is that it did do it, but the code does not compile.  The only fix 
> >I can find is to change F1 to look like:
> >         void F1( A a ) { B b(a); F2(b); }
> >Which would seem like what the compiler ought to do automatically 
> >anyway.  Instead I get a main error that:
> >         Cannot find B::B(B)
> >
> >I have searched the docs and the news groups and can't seem to find any 
> >docage on this.  Is there a compile switch I need to get the auto creation 
> >of the temp?  Is there another work around besides changing all the code 
> >that does that sort of thing to create my own temp explicitly?  BTW: this 
> >code compiles fine under MSVC 6 and Kylix 3.
> >
> >thanks in advance.
> >
> >Michael Hunley
> >Senior Engineer
> >PocketPurchase, Inc.  
> >


-- 
Matthias Oltmanns

Tel: 04421-1543-274
mail: Mathias dot Oltmanns dot Oltmanns at sysde dot eads dot net


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