delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/05/01/17:19:31

Message-ID: <20030501211903.51108.qmail@web13002.mail.yahoo.com>
Date: Thu, 1 May 2003 14:19:03 -0700 (PDT)
From: Thomas Tutone <thomas8675309 AT yahoo DOT com>
Subject: Re: "Error: implicit declaration ..."
To: djgpp AT delorie DOT com
Cc: j DOT j DOT konkle-parker AT larc DOT nasa DOT gov
MIME-Version: 1.0

"Joel Konkle-Parker" wrote:
> I'm attempting to compile the attached files, and I 
> keep getting the
> following error:
> 
> --
> Compiling: string5.cc
> In function 'class istream & operator >>(istream &, 
> string &)':
> String5.cc(105) Error: implicit declaration of 
> function 'int 
> memset(...)' There were some errors
> 
> What's going on here?
>

A couple things. First, memset is prototyped in
<cstring> and in the C header <string.h> (which you
shouldn't use, since this is a C++ program), neither
of which you #include. So the compiler sees your use
of memset before it has been prototyped, which is an
error in standard C++, I believe. Second, you are
using a mix of old-style (i.e., pre-standard) C++ and
C, which will cause you problems in any event.

I take it this is old code that you are trying to
modify. You will find that old code written in
pre-standard C++ can be quite brittle when exposed to
a modern C++ compiler. A dirty fix is to add the
following declaration before you use memset:

  void *memset(void *buffer, int ch, size_t num);

But that will likely cause problems down the road if
this code is modified. A better solution would be to
switch all your deprecated headers (like <iostream.h>)
to their standard equivalents (like <iostream>) and
modify the code accordingly to use the std namespace. 
Then you could add:

#include <cstring>
using std::memset;

But the best solution is to stop using your own custom
versions of string and vector. The versions of string
and vector in the standard library are far superior to
yours. Moreover, if you insist on using custom
versions, at least give them different names than
"string" and "vector" so that you don't have name
collisions with the standard library's down the road.

Finally, if I'm wrong, and you wrote this code
yourself, you should get yourself a good C++ book,
like Koenig and Moo's Accelerated C++, to teach you
standard C++, as well as a good reference like
Stroustrup's The C++ Programming Language (3d edition
or special edition).

Good luck.

Best regards,

Tom






__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

- Raw text -


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