delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/07/29/15:37:32

Message-ID: <398326AF.4C7E65CE@puckbell.net>
From: Wesel <nospam AT puckbell DOT net>
X-Mailer: Mozilla 4.73 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: friend/member function bug?
Lines: 64
Date: Sat, 29 Jul 2000 11:47:11 -0700
NNTP-Posting-Host: 63.197.122.98
X-Complaints-To: abuse AT pacbell DOT net
X-Trace: news.pacbell.net 964895976 63.197.122.98 (Sat, 29 Jul 2000 11:39:36 PDT)
NNTP-Posting-Date: Sat, 29 Jul 2000 11:39:36 PDT
Organization: SBC Internet Services
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Is there a bug when you give friend functions and member functions the
same name?  I made this code:

------------------------------------------------
// In test.h

#include <iostream>
using std::cout;

template <class Type>
struct foo
{
	Type bar;

	foo& operator<<(const Type& e)
	{
		bar = e;
		return *this;
	}

	friend ostream& operator<<<>(ostream& os,foo<Type> const& q);
};

template <class Type> inline ostream& operator<<(ostream& os,foo<Type>
const& q)
{
  foo<Type> const* temp = &q;
  return os << temp->bar << endl;
}

------------------------------------------------

------------------------------------------------
// In test.cpp
#include "test.h"
#include <iostream>

void main(void)
{
	foo<int> test;
	cout << test;
}

------------------------------------------------

And got this compiler error:

test.h: In instantiation of `foo<int>':
test.cpp:6:   instantiated from here
test.h:15: invalid use of undefined type `struct foo<int>'
test.h:16: forward declaration of `struct foo<int>'
test.h:15: confused by earlier errors, bailing out

Someone suggested that gcc v. 2.95.2 has a bug when you try to declare
operator<< as a friend and <class>::operator<< as a member.  Is this
true, and if so is there any way to work around it?


Tasci

-- 

To send me an email, just replace the @ and the .
     -----wassdamo at pacbell dot net

- Raw text -


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