🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #1090

Re: default arguments vs templates

#1090
From: Mike Stump
Date: Fri, 06 Nov 1992 08:29
47 lines
2038 bytes
This problem has been fixed, and should not exist in the next release
of gcc.

> Date: Mon, 31 Aug 92 16:14:46 EDT
> From: rtm@das.harvard.edu
> Message-Id: <9208312014.AA02681@virtual7.harvard.edu>
> To: bug-g++@prep.ai.mit.edu

> I'm running g++ 2.2.2 on a SPARCstation ELC with SunOS 4.1.2.  I want
> to have a default argument to a method of a templated class.  I think
> the following code should work, but it produces an error message.
> Repeating the default in the definition (as well as the declaration)
> fixes the error message, but section 8.2.6 in the Annotated Reference
> Manual says such repetition is illegal.

> template<class T> class b{
> private:
>     T x;
> public:
>     void Print(int x = 10);
> };

> template<class T> void
> b<T>::Print(int x) // x = 10 fixes the error message.
> {
> }

> main()
> {
>     b<int> zz;

>     zz.Print(99);
> }

> Here's the output from g++ -v:

> Reading specs from /home/glan/lib/gcc-lib/sun4/2.2.2/specs
> gcc version 2.2.2
>  /home/glan/lib/gcc-lib/sun4/2.2.2/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG
> __=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__spa
> rc -D__sun -D__unix zoid.cc /usr/tmp/cca02675.i
> GNU CPP version 2.2.2 (sparc)
>  /home/glan/lib/gcc-lib/sun4/2.2.2/cc1plus /usr/tmp/cca02675.i -quiet -dumpbase
> zoid.cc -version -o /usr/tmp/cca02675.s
> GNU C++ version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
> zoid.cc: In function `int  main ()':
> zoid.cc:7: template for method `Print' doesn't match any in class `b<int>'
Technical Details
Message-ID: <9211060829.AA01518@cygnus.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!hp-cv!sdd.hp.com!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cygnus.com!mrs

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!hp-cv!sdd.hp.com!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cygnus.com!mrs
From: mrs@cygnus.com (Mike Stump)
Newsgroups: gnu.g++.bug
Subject: Re:  default arguments vs templates
Message-ID: <9211060829.AA01518@cygnus.com>
Date: 6 Nov 92 08:29:30 GMT
Article-I.D.: cygnus.9211060829.AA01518
Sender: gnulists@ai.mit.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 47
Approved: bug-g++@prep.ai.mit.edu