where did I do wrong? (myString class) Please help! I have to turn in tomorrow
-
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;
-
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;
So is the modified code OK now? :-D
Maxwell Chen
-
So is the modified code OK now? :-D
Maxwell Chen
-
Thanks for the help, I haven't check it yet. but I think it will work fine. Thanks again from foxele
-
Thanks for the help, I haven't check it yet. but I think it will work fine. Thanks again from foxele
I have sent you another email about the reason having written the email address that way ... :-D
Maxwell Chen
-
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!
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
-
I have sent you another email about the reason having written the email address that way ... :-D
Maxwell Chen
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
-
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
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