cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/15/16:30:18

From: gamma AT space DOT net (gamma)
Newsgroups: comp.os.msdos.djgpp
Subject: Linking problems with overloading operator<<
Date: Thu, 15 Oct 1998 20:04:32 GMT
Organization: United States Internet, Inc.
Lines: 44
Message-ID: <362651bd.2990955@news.usit.net>
NNTP-Posting-Host: dialup32.tnjoh.usit.net
Mime-Version: 1.0
X-Trace: news.usit.net 908481781 11788 205.241.204.117 (15 Oct 1998 20:03:01 GMT)
NNTP-Posting-Date: 15 Oct 1998 20:03:01 GMT
X-Newsreader: Forte Agent 1.5/32.452
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I am having problems linking files that have the insertion and
extraction operators overloaded.... here is a little snippet of
code...

//Golfer.h

#ifndef _GOLFER_H_
#define _GOLFER_H_

#include <string>
#include <iostream>
using namespace std;

class Golfer  
{
	friend ostream& operator<<(ostream&, const Golfer&);
	friend istream& operator>>(istream&, Golfer&);
.
.
.
}

ostream& operator<<(ostream& gout, const Golfer& outGolfer)
{
	gout << outGolfer.PIT << "\t" << outGolfer.name << "\t" <<
outGolfer.rank;
	return gout;
}
.
.
.

#endif

This complies okay but returns these linker errors.

Error:  Golfer.o :  In fraction 'operator<<(ostream &, Golfer const
&)':
Error:  Golfer.cpp(.text+0x4): multiple definition of
'operator<<(ostream &, Golfer const &)'

Any help would be greatly appreciated 
Thanks
Charlie Mac.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019