* Help with an overloading istream
@ 2004-03-08 20:30 Kevin Stedman
2004-03-08 20:54 ` Eljay Love-Jensen
0 siblings, 1 reply; 3+ messages in thread
From: Kevin Stedman @ 2004-03-08 20:30 UTC (permalink / raw)
To: gcc-help
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=us-ascii, Size: 1660 bytes --]
I am porting some code from Solaris to Linux. This
code is overloading the operator>> of istream. When I
compile I get the following errors:
String.C: In function 'istream& operator>>(istream&,
String&)':
String.C:45: invalid use of undefined type 'struct
istream'
String.h:20: forward declaration of 'struct istream'
If some one could please tell me what is going on I
would appreciate it. This does work and compile on
Solaris. I think I am missing something put I do not
known what it is.
Here is the code for String.h
#ifndef _String_h
#ifdef _LINUX_
#include <iostream>
#endif
class istream;
class String {
friend istream &operator>>(istream &, String &);
public:
String();
String(const String &);
~String();
const String &operator=(const String &);
int operator!=(const char *) const;
operator const char *() const
{ return ptr; }
protected:
private:
char *ptr;
};
#endif
Here is the code for String.C:
#include <string.h>
#ifdef _LINUX_
#include <iostream>
#else
#include <iostream.h>
#endif
#include "String.h"
String::~String()
{
delete [] ptr;
}
String::String(void)
: ptr(new char[1])
{
ptr[0] = 0;
}
int
String::operator!=(const char *cmp) const
{
return strcmp(ptr,cmp);
}
istream &
operator>>(istream &in, String &s)
{
char buffer[256];
buffer[0] = 0;
in.get(buffer,256);
delete [] s.ptr;
s.ptr = new char [strlen(buffer) + 1];
strcpy(s.ptr,buffer);
return in;
}
Any help in advance is appreciated
Kevin
__________________________________
Do you Yahoo!?
Yahoo! Search - Find what youre looking for faster
http://search.yahoo.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Help with an overloading istream
2004-03-08 20:30 Help with an overloading istream Kevin Stedman
@ 2004-03-08 20:54 ` Eljay Love-Jensen
2004-03-08 21:29 ` Kevin Stedman
0 siblings, 1 reply; 3+ messages in thread
From: Eljay Love-Jensen @ 2004-03-08 20:54 UTC (permalink / raw)
To: Kevin Stedman, gcc-help
Hi Kevin,
What version of GCC are you using on Solaris?
What version of GCC are you using on Linux?
It appears that your String.h file is not namespace savvy.
--Eljay
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Help with an overloading istream
2004-03-08 20:54 ` Eljay Love-Jensen
@ 2004-03-08 21:29 ` Kevin Stedman
0 siblings, 0 replies; 3+ messages in thread
From: Kevin Stedman @ 2004-03-08 21:29 UTC (permalink / raw)
To: gcc-help
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=us-ascii, Size: 485 bytes --]
GCC 3.2.2 on Linux. For Solaris I could not tell you.
I think they use the Solaris provided compilers.
Kevin
--- Eljay Love-Jensen <eljay@adobe.com> wrote:
> Hi Kevin,
>
> What version of GCC are you using on Solaris?
>
> What version of GCC are you using on Linux?
>
> It appears that your String.h file is not namespace
> savvy.
>
> --Eljay
>
__________________________________
Do you Yahoo!?
Yahoo! Search - Find what youre looking for faster
http://search.yahoo.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-03-08 21:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-08 20:30 Help with an overloading istream Kevin Stedman
2004-03-08 20:54 ` Eljay Love-Jensen
2004-03-08 21:29 ` Kevin Stedman
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).