Article View: gnu.g++.bug
Article #1005g++ 2.2.2 -- class templates and const member functions
From: Dan Yergeau
Date: Thu, 01 Oct 1992 09:14
Date: Thu, 01 Oct 1992 09:14
46 lines
1660 bytes
1660 bytes
Templates do not handle const member functions properly. Const member
functions do work in non-template classes.
This probably occurs on all machines/OS. I've tried it on an SGI 4D
(mips-sgi-irix4) running Irix 4.0.1 and a Intel '386 (i386-sysv)
running vanilla SysV 3.2.
The sample source file is below. The command line to show the problem
is
% g++ -DKONST=const -c bug.cc
bug.cc: In function `int main ()':
bug.cc:12: template for method `bar' doesn't match any in class `Foo<int>'
Dropping off the -DKONST=const compiles the file successfully.
============================================================================
#ifndef KONST
#define KONST
#endif
// Demonstation purposes only. I don't really write code like this.
template<class T> class Foo {
public:
int bar() KONST;
private:
int _n;
};
template<class T> int Foo<T>::bar() KONST
{
return _n;
}
int main()
{
// Use the template to generate the definitions for an
// instantiation of Foo<T>
Foo<int> f;
}
============================================================================
--
Dan Yergeau
yergeau@gloworm.Stanford.EDU
Technical Details
Message-ID:
<9210012314.AA12509@outpost.Stanford.EDU>Path:
arc1-ca.pugleaf.net!sparky!uunet!convex!news.utdallas.edu!wupost!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!outpost.stanford.edu!yergeauShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!convex!news.utdallas.edu!wupost!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!outpost.stanford.edu!yergeau From: yergeau@outpost.stanford.edu (Dan Yergeau) Subject: g++ 2.2.2 -- class templates and const member functions Message-ID: <9210012314.AA12509@outpost.Stanford.EDU> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Thu, 1 Oct 1992 09:14:11 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 48