Click here to Skip to main content
15,886,851 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hello!
I'm using C++ builder 6.0 and coding this:
XML
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <iostream.h>
#include <conio.h>
#include <string.h>
#pragma argsused
class Mystring {  //now with conversion operator
    char *s;
    int size;
    public:
    Mystring(const char *);
    Mystring();
    operator const char * () { return s; } //conversion operator
    //...
};
int main(int argc, char* argv[])
{
    Mystring str("hello world");
    int n = strcmp(str, "Hello");
    cout<<str<<endl;
    getch();
    return 0;
}

and got this error:
[Linker Error] Error: Unresolved external 'Mystring::Mystring(const char *)' referenced from E:\_TPU\_KI 1 NAM 3\_OOP\LAB5\DEBUG_BUILD\UNIT.OBJ

It's the same error when compiling in Visual C++ 2008.
May someone tell me what is it? how can i solve it? Is my program correct?
Thank you very much!
Posted

I don't know if you posted your entire code, but if you did, than you only declare the constructors, you never actually define them. Try changing the class definition to this:


C#
class Mystring {  //now with conversion operator
    char *s;
    int size;
    public:
    Mystring(const char *str)
    {
         //do something here - like make a copy of str and assign it to s
    }
    Mystring()
    {
         //do something here - like set s to NULL
    }
    operator const char * () { return s; } //conversion operator
    //...
};


You may also define the constructors outside the class - but my suggestion is to do some reading about c++ first. Good luck!!
 
Share this answer
 
v2
Comments
lijiantao 16-Jan-11 23:02pm    
++
You can check if Mystring(const char *) has defined properly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900