Topic: Is this C++ code ?


Author: marek@iiasa.ac.at (Marek MAKOWSKI)
Date: 1996/11/19
Raw View
IMHO the following is legal C++ :

// Also BCC 5.0 works, if the following line is uncommented
// does the standard require the declaration in the following line ?
// template <class I, class F>  class LP_prob;

template <class I, class F> class LP_var {
 friend class LP_prob<I,F>;  // error reported by BCC 5.0
 // ...
};

The code duplicated above compiles with SunPro, Watcom and BCC v. 4.52
However, BCC 5.0 reports:
  ... Declaration terminated incorectly.

If the  commented above declaration is uncommented, then the compilation
runs OK.

Q: is the commented declaration really necessary ?

Thanks in advance for your comments,
Marek


--
                  Marek Makowski  | Email: marek@iiasa.ac.at
         International Institute  | URL: http://www.iiasa.ac.at/~marek
    for Applied Systems Analysis  | Phone: (+43-2236) 807.561
       A-2361 Laxenburg, Austria  | Fax:   (+43-2236) 71.313



[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: Jason Merrill <jason@cygnus.com>
Date: 1996/11/19
Raw View
>>>>> Marek MAKOWSKI <marek@iiasa.ac.at> writes:

> IMHO the following is legal C++ :

> // Also BCC 5.0 works, if the following line is uncommented
> // does the standard require the declaration in the following line ?
> // template <class I, class F>  class LP_prob;

> template <class I, class F> class LP_var {
>  friend class LP_prob<I,F>;  // error reported by BCC 5.0
>  // ...
> };

> The code duplicated above compiles with SunPro, Watcom and BCC v. 4.52
> However, BCC 5.0 reports:
>   ... Declaration terminated incorectly.

> If the  commented above declaration is uncommented, then the compilation
> runs OK.

> Q: is the commented declaration really necessary ?

Yes.  All names must be declared before they are used.  Most old template
implementations did not do name binding and syntactic checks on the
template definition, but the WP requires immediate name binding and allows
immediate syntax diagnostics, so I imagine all compilers will require that
declaration before long.  The next release of g++ will.

Jason
---
[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]