Topic: const template argument?
Author: "Michael S. Tsirkin" <mtsirkin@iil.intel.com>
Date: 1998/02/16 Raw View
Hello!
Could someone pls help me to understand if the following is the
compiler's bug or not?
template <class T>
void f(const T& t)
{
T m;
}
int
main()
{
f(false);
f(1);
f(1.0);
return 0;
}
VC++5.0 says:
error C2734: 'm' : const object must be initialized if not extern.
It thinks 'm' is const! Why?
If possible , pls Cc: mailto:mtsirkin@iil.intel.com
Thanks,
mst
--
Michael S. Tsirkin Intel, Haifa, Israel; Mail stop: IDC-4C
Work telephone in Israel 435-5658 ( Local in Israel 04-8655658 )
mailto:mtsirkin@iil.intel.com ; http://www.iil.intel.com/~mtsirkin/
> Four things are to be strengthened : Torah, and good deeds,
> prayer and one's good manners (Berachoth)
---
[ 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: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1998/02/16 Raw View
Michael S. Tsirkin wrote:
> Could someone pls help me to understand if the following is the
> compiler's bug or not?
It is.
> template <class T>
> void f(const T& t)
> {
> T m;
> }
>
> int
> main()
> {
> f(false);
> f(1);
> f(1.0);
> return 0;
> }
>
> VC++5.0 says:
> error C2734: 'm' : const object must be initialized if not extern.
> It thinks 'm' is const! Why?
You don't say which line cause the error, but T should be
unqualified bool, int, float. It shouldn't be const.
--
Valentin Bonnard mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://www.pratique.fr/~bonnardv/
---
[ 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: "Brock" <peabody@npcinternational.com>
Date: 1998/02/16 Raw View
I compiled your code with MSVC 5.0 sp2, no errors, just 3 warnings that m
was unreferenced.
Michael S. Tsirkin wrote in message <34E82D54.FE6125C5@iil.intel.com>...
>Hello!
>Could someone pls help me to understand if the following is the
>compiler's bug or not?
>
>template <class T>
> void f(const T& t)
>{
> T m;
>}
>
>int
>main()
>{
> f(false);
> f(1);
> f(1.0);
> return 0;
>}
>
>VC++5.0 says:
>error C2734: 'm' : const object must be initialized if not extern.
>It thinks 'm' is const! Why?
>
>If possible , pls Cc: mailto:mtsirkin@iil.intel.com
>
>Thanks,
>mst
<<
---
[ 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: "Chuck McCorvey" <chuckm@solutionware.com>
Date: 1998/02/17 Raw View
I tried with VC++ 5.0 SP3 - it also worked just fine (if you ignore the 3
warnings).
--
Chuck McCorvey
Creative SolutionWare, Inc.
Brock <peabody@npcinternational.com> wrote in article
<6cagq1$2kc$1@news4.ispnews.com>...
> I compiled your code with MSVC 5.0 sp2, no errors, just 3 warnings that m
> was unreferenced.
>
> Michael S. Tsirkin wrote in message <34E82D54.FE6125C5@iil.intel.com>...
> >Hello!
> >Could someone pls help me to understand if the following is the
> >compiler's bug or not?
> >
> >template <class T>
> > void f(const T& t)
> >{
> > T m;
> >}
> >
> >int
> >main()
> >{
> > f(false);
> > f(1);
> > f(1.0);
> > return 0;
> >}
> >
> >VC++5.0 says:
> >error C2734: 'm' : const object must be initialized if not extern.
> >It thinks 'm' is const! Why?
> >
> >If possible , pls Cc: mailto:mtsirkin@iil.intel.com
> >
> >Thanks,
> >mst
[ 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 ]