error C2039

This is a discussion on error C2039 within the C++ Programming forums, part of the General Programming Boards category; I'm new to C++ and this is example code (only part of the code where I'm recieving the error) from ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    2

    error C2039

    I'm new to C++ and this is example code (only part of the code where I'm recieving the error) from my text book. I'm receiving the follow error:

    C:\CSC311\CHAP03\RealEstate\String2.cpp(153) : error C2039: 'strcpy' : is not a member of 'std'

    #include "STRING2.h"
    #include <cctype>
    #include <fstream>
    #include <iostream>
    #include <cstring>

    void StrType::CopyString(StrType& newString)
    {
    using namespace std;
    std::strcpy(newString.letters, letters);}

    void StrType:perator=(const StrType& otherString)
    {
    using namespace std;
    std::strcpy(letters, otherString.letters);
    }

    Can anyone give me a hint or clue as to why or where to look?

    Thanks for any help.

    Rex

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Just use strcpy() instead of std::strcpy().
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    2
    Thanks. That worked like a charm!

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Can anyone give me a hint or clue as to why or where to look?
    Your compiler is too old to realize that all of the non-deprecated C library is in the std namespace. That's why, and you can get around it simply by not qualifying the C functions that you use or to be more portable with compliant compilers, use a using directive:
    Code:
    using namespace std;
    Though that has problems of its own, it's the method I used for some time with VC++ 6.0 because good style can avoid the problems most of the time. Those are two ways to work around the problem. Another is to add any of your C headers to the std namespace:
    Code:
    namespace std {
      #include <cstring>
    }
    But that's not really the best idea. A slightly better solution would be to declare your functions manually within the std namespace:
    Code:
    #include <cstring>
    namespace std {
      char *strcpy(char *dst, const char *src);
    }
    That's not really the best idea either, because the declarations are easy to get wrong, and it's rather verbose for most tastes, so you should stick to the aforementioned non-portable style or the using directive.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21