Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. where did I do wrong? (myString class) Please help! I have to turn in tomorrow

where did I do wrong? (myString class) Please help! I have to turn in tomorrow

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++debuggingquestionworkspace
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    foxele
    wrote on last edited by
    #1

    I wrote a string class and try to test with a very simple driver program, but there are some erros, can somebody help me figure out my mistakes? thank you! --------------Configuration: main - Win32 Debug-------------------- Compiling... main.cpp Linking... main.obj : error LNK2001: unresolved external symbol "public: __thiscall myString::~myString(void)" (??1myString@@QAE@XZ) main.obj : error LNK2001: unresolved external symbol "class ostream & __cdecl operator<<(class ostream &,class myString const &)" (??6@YAAAVostream@@AAV0@ABVmyString@@@Z) main.obj : error LNK2001: unresolved external symbol "public: __thiscall myString::myString(char const *)" (??0myString@@QAE@PBD@Z) Debug/main.exe : fatal error LNK1120: 3 unresolved externals Error executing link.exe. main.exe - 4 error(s), 0 warning(s) ____________________________________________________________________________ myString.h file: //myString #ifndef MYSTRING_H #define MYSTRING_H #include class myString{ friend ostream &operator<<(ostream &, const myString &); friend istream &operator>>(istream &, myString &); public: myString( const char * = ""); myString(const myString &); ~myString(); const myString &operator= (const myString &); //assign string myString &operator+= (const myString &); int operator! () const; //empty string int operator== (const myString &) const; int operator!= (const myString &) const; int operator< (const myString &) const; int operator> (const myString &) const; int operator>= (const myString &) const; int operator<= (const myString &) const; char &operator[] (int); myString &operator()(int, int); int getLength() const; // void toUpper (myString &); // void toLower (myString &); private: char* sPtr; int length; }; #endif ________________________________________________________________________ myString.cpp file //myString.cpp #include #include #include #include"myString.h" myString::myString(const char *s) { lengh = strlen(s); sPtr = new char[lengh +1]; assert(sPtr!=0); strcpy(sPtr, s); } //convention constructor myString::myString(const myString ©) { lengh = copy.length; sptr = new char [length +1]; assert(sPtr!= 0 ); strcpy(sPtr, copy.sPtr); } //copy constructor myString::~myString() { delete [] sPtr; } //destructor const myString &myString::operator = (const myString &right) { if(&right! = this) { delete [] sPtr; length = right.length;

    M 1 Reply Last reply
    0
    • F foxele

      I wrote a string class and try to test with a very simple driver program, but there are some erros, can somebody help me figure out my mistakes? thank you! --------------Configuration: main - Win32 Debug-------------------- Compiling... main.cpp Linking... main.obj : error LNK2001: unresolved external symbol "public: __thiscall myString::~myString(void)" (??1myString@@QAE@XZ) main.obj : error LNK2001: unresolved external symbol "class ostream & __cdecl operator<<(class ostream &,class myString const &)" (??6@YAAAVostream@@AAV0@ABVmyString@@@Z) main.obj : error LNK2001: unresolved external symbol "public: __thiscall myString::myString(char const *)" (??0myString@@QAE@PBD@Z) Debug/main.exe : fatal error LNK1120: 3 unresolved externals Error executing link.exe. main.exe - 4 error(s), 0 warning(s) ____________________________________________________________________________ myString.h file: //myString #ifndef MYSTRING_H #define MYSTRING_H #include class myString{ friend ostream &operator<<(ostream &, const myString &); friend istream &operator>>(istream &, myString &); public: myString( const char * = ""); myString(const myString &); ~myString(); const myString &operator= (const myString &); //assign string myString &operator+= (const myString &); int operator! () const; //empty string int operator== (const myString &) const; int operator!= (const myString &) const; int operator< (const myString &) const; int operator> (const myString &) const; int operator>= (const myString &) const; int operator<= (const myString &) const; char &operator[] (int); myString &operator()(int, int); int getLength() const; // void toUpper (myString &); // void toLower (myString &); private: char* sPtr; int length; }; #endif ________________________________________________________________________ myString.cpp file //myString.cpp #include #include #include #include"myString.h" myString::myString(const char *s) { lengh = strlen(s); sPtr = new char[lengh +1]; assert(sPtr!=0); strcpy(sPtr, s); } //convention constructor myString::myString(const myString ©) { lengh = copy.length; sptr = new char [length +1]; assert(sPtr!= 0 ); strcpy(sPtr, copy.sPtr); } //copy constructor myString::~myString() { delete [] sPtr; } //destructor const myString &myString::operator = (const myString &right) { if(&right! = this) { delete [] sPtr; length = right.length;

      M Offline
      M Offline
      Maxwell Chen
      wrote on last edited by
      #2

      So is the modified code OK now? :-D


      Maxwell Chen

      F 1 Reply Last reply
      0
      • M Maxwell Chen

        So is the modified code OK now? :-D


        Maxwell Chen

        F Offline
        F Offline
        foxele
        wrote on last edited by
        #3

        Thanks for the help, I haven't check it yet. but I think it will work fine. Thanks again from foxele

        F M 2 Replies Last reply
        0
        • F foxele

          Thanks for the help, I haven't check it yet. but I think it will work fine. Thanks again from foxele

          F Offline
          F Offline
          foxele
          wrote on last edited by
          #4

          Can u send those modified code as attachment in header file and source file, cause I couldn't download them, I don't know why thanks agian!

          M 1 Reply Last reply
          0
          • F foxele

            Thanks for the help, I haven't check it yet. but I think it will work fine. Thanks again from foxele

            M Offline
            M Offline
            Maxwell Chen
            wrote on last edited by
            #5

            I have sent you another email about the reason having written the email address that way ... :-D


            Maxwell Chen

            F 1 Reply Last reply
            0
            • F foxele

              Can u send those modified code as attachment in header file and source file, cause I couldn't download them, I don't know why thanks agian!

              M Offline
              M Offline
              Maxwell Chen
              wrote on last edited by
              #6

              I did send them in attachment form. Check the lower part of the mail! There are [Download] links. :-D In the email...

              My texts,

              (blue line) Your text...

              (Still blue line) Your original attachment texts...

              Do you Yahoo!?

              (No blue line since here) My attachments!


              Maxwell Chen

              1 Reply Last reply
              0
              • M Maxwell Chen

                I have sent you another email about the reason having written the email address that way ... :-D


                Maxwell Chen

                F Offline
                F Offline
                foxele
                wrote on last edited by
                #7

                Maxwell, did you test the myString class with your c++ compiler? I still got the same four errors about my destructor and operator<< and constructor. If it works fine in your computer, then it is the problem of my compiler. Please let me know . Thank You So Much from foxele

                M 1 Reply Last reply
                0
                • F foxele

                  Maxwell, did you test the myString class with your c++ compiler? I still got the same four errors about my destructor and operator<< and constructor. If it works fine in your computer, then it is the problem of my compiler. Please let me know . Thank You So Much from foxele

                  M Offline
                  M Offline
                  Maxwell Chen
                  wrote on last edited by
                  #8

                  foxele wrote: Maxwell, did you test the myString class with your c++ compiler? I still got the same four errors about my destructor and operator<< and constructor. If it works fine in your computer, then it is the problem of my compiler. Please let me know . Yes, with Visual C++ 6.0, I built it, and ran it. The code compiled without any error or warning. And the output was correct ("Happy"... something). Are you sure that you've downloaded the correct code? Or you just made a mistake that you copied the original code included in the text part of the reply? Or you didn't replace the code in the project with new one? Check the comments in the cpp file. I have moved some comments from the end of function bodies to the beginning of function bodies. If it is such kind, then it's a new one. For example: **// Conventional constructor** myString::myString() {   // ... } To isolate the problem from your making a mistake replacing files or your compiler's got problem, this time I will send you the whole project in ZIP form. Please visit WinZip[^] to get a zip tool. Thanks.


                  Maxwell Chen

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups