[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: G++ rejects legal code



"Martin v. Loewis" wrote:

> I think so. I fail to see the bug in your report, though. Your code is
> illegal (or, rather, ill-formed - some GNU coding style advises us not
> to claim that you are breaking the law by writing the code).
>
> > template <class _TW, class _TTWO>
> > struct SGBMb : public SGBb <_TW>
> > {
> >  typedef _TTWO _TWO;
> >  _TWO osy;
> >
> >  SGBMb <_TW, _TWO> (_TW _sy, _TWO _osy, void* _st)
> >   : sy (_sy), osy (_osy), st (_st) {}
> > };
>
> The class SGBMb (i.e. all instantiations of the class template) has
> only one data member, namely osy. The members sy and st are defined in
> the base class, so they must not be mentioned in the member
> initializer of the derived class. Instead, you should write

Why only one data member?  Members sy and st are public in the base class.
Initialization in the constructor body works OK. Moreover, (week argument, but)
Visual C++ compiles this OK.


> template <class _TW, class _TTWO>
> struct SGBMb : public SGBb <_TW>
> {
>  typedef _TTWO _TWO;
>  _TWO osy;
>
>  SGBMb <_TW, _TWO> (_TW _sy, _TWO _osy, void* _st)
>   : SGBb<_TW>(_sy, _st), osy (_osy) {}
> };

(or initialize sy and st in {} )




Reply to: