Topic: [Q] Correct Syntax?


Author: "Gabor Greif" <gabor.greif@no.drsolomon.com>
Date: 1998/02/11
Raw View
I wonder if this is correct:

#include <typeinfo.h>

struct A
{
 A(const type_info& i = typeid(A)) : info(i) { }
 const type_info& info;
};

Note the usage of "typeid(A)" as a default argument.
My compiler complains: "illegal use of incomplete struct: A"
I do not see any reason why using A should be forbidden in default
argument initializations...

So, is the above syntax correct, or is my compiler right?

Thanks,

 Gabor



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: James Kuyper <kuyper@wizard.net>
Date: 1998/02/12
Raw View
Gabor Greif wrote:
>
> I wonder if this is correct:
>
> #include <typeinfo.h>
>
> struct A
> {
>         A(const type_info& i = typeid(A)) : info(i) { }
>         const type_info&        info;
> };
>
> Note the usage of "typeid(A)" as a default argument.
> My compiler complains: "illegal use of incomplete struct: A"
> I do not see any reason why using A should be forbidden in default
> argument initializations...
>
> So, is the above syntax correct, or is my compiler right?

Yes, your compiler is right. typeid(A) requires a complete type, and A
isn't complete yet at that point.


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]