C++ constructors called as args
Michael Hunley
mhunley@pocketpurchase.com
Mon Mar 3 07:57:00 GMT 2003
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.
More information about the Gcc-help
mailing list