Article View: gnu.g++.bug
Article #862default arguments vs templates
From: rtm
Date: Mon, 31 Aug 1992 20:14
Date: Mon, 31 Aug 1992 20:14
39 lines
1679 bytes
1679 bytes
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:
<9208312014.AA02681@virtual7.harvard.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!das.harvard.edu!rtmShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!das.harvard.edu!rtm From: rtm@das.harvard.edu Subject: default arguments vs templates Message-ID: <9208312014.AA02681@virtual7.harvard.edu> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Mon, 31 Aug 1992 20:14:46 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 40