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: Class casting


Interestingly enough, if you did this:

int main() {
        B b;
        C* c = new C(b);
}

It will compile and work as expected. The constructor wants an A, a B is
an A, so everything is fine.

Why one needs to declare the B first, rather than instantiating the
temporary as in the code below, I have no idea. Can anyone shed some
light on this?

Justin

On Wed, 2003-07-02 at 12:09, Greg Davey wrote:
...
> int main(){
>     C* c = new C(B()); 
>     c->doOtherStuff();
>     return 0;
> }
> 



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