public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Do friend functions work in templates
@ 1998-12-09 12:32 Michael Bletzinger
  1998-12-09 12:54 ` Alexandre Oliva
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Bletzinger @ 1998-12-09 12:32 UTC (permalink / raw)
  To: egcs general

I have bullheaded through the available documentation to determine how
egcs implements templates (and learning templates at the same time). 
But now I have reached an impass.  I am trying to declare a function to
be a friend of a template and it does not seem to be working. Please
don't hesitate to tell me if I am overlooking something.

My class template:

template <class ENUM_T, int MIN_T = 0> class EnumTemplate
{
public:
  friend ostream& operator << (ostream& s, const EnumTemplate& Me);
   ^ notice friend function.
  EnumTemplate(const string Labels);
  inline EnumTemplate(ENUM_T Value = 0);
  inline void Set(ENUM_T Value);
  inline void Set(int Value);
  inline ENUM_T Get();
  inline const string& Label() const;
  inline const string& Name() const;
  inline const string& Abbrev() const;
  inline ENUM_T Max();
private:
  static vector<string> Labels_m;
  static string Name_m;
  static string Abbrev_m;
  ENUM_T Value_m;
  bool IsIllegal_m;
  int IllegalValue_m;
};

My friend function template which comes after the class template:

template <class ENUM_T, int MIN_T> 
ostream& operator << (ostream& s, const EnumTemplate<ENUM_T, MIN_T>& Me)
{
  if(Me.IsIllegal_m)
  {
    s<<"IL:"<<Me.IllegalValue_m;
  }
  else
  {
    s<<Me.Label();
  }
  return s;
}

The compiler warning and error:

/opt/egcs/bin/g++ -c -Wall -g -I.  TA_Enums.C
In file included from TA_Enums.H:3,
                 from TA_Enums.C:1:
EnumTemplate.H:13: warning: friend declaration `class ostream & operator
<<(class ostream &, const class EnumTemplate<ENUM_T,MIN_T> &)'
EnumTemplate.H:13: warning:   declares a non-template function
EnumTemplate.H:13: warning:   (if this is not what you intended, make
sure
EnumTemplate.H:13: warning:   the function template has already been
declared,
EnumTemplate.H:13: warning:   and add <> after the function name here)
[-snip-]
/opt/egcs/bin/g++ -o TestA -Wall -g TA_Enums.o  TestA.o 
Undefined			first referenced
 symbol  			    in file
operator<<(ostream &, EnumTemplate<LandUnitTypeType, 0> const &)TestA.o
operator<<(ostream &, EnumTemplate<AirUnitTypeType, 0> const &)TestA.o
operator<<(ostream &, EnumTemplate<SurfUnitTypeType, 0> const &)TestA.o
operator<<(ostream &, EnumTemplate<SubSurfUnitTypeType, 0> const
&)TestA.o

I have tried prototyping the function in front of the class template but
this does not seem to help

The environment:
SunOS ultra2a 5.6 Generic sun4u sparc SUNW,Ultra-2
egcs version 1.1.1

	Thanks in advance
	Michael
-- 
First Rule of Engineering Design:
It is wiser to present an unworkable design rather
than a workable design to speed up the revision process
Phone (voice): (812)854-1101    (fax):   (812)854-3437

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Do friend functions work in templates
  1998-12-09 12:32 Do friend functions work in templates Michael Bletzinger
@ 1998-12-09 12:54 ` Alexandre Oliva
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Oliva @ 1998-12-09 12:54 UTC (permalink / raw)
  To: Michael Bletzinger; +Cc: egcs general

On Dec  9, 1998, Michael Bletzinger <michael.bletzinger@ssa.crane.navy.mil> wrote:

> don't hesitate to tell me if I am overlooking something.

http://egcs.cygnus.com/faq.html#friend

-- 
Alexandre Oliva  http://www.dcc.unicamp.br/~oliva  aoliva@{acm.org}
oliva@{dcc.unicamp.br,gnu.org,egcs.cygnus.com,samba.org}
Universidade Estadual de Campinas, SP, Brasil

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1998-12-09 12:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-09 12:32 Do friend functions work in templates Michael Bletzinger
1998-12-09 12:54 ` Alexandre Oliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).