C ++ Builder 6.0中的链接错误 [英] Linked error in C++ builder 6.0

查看:85
本文介绍了C ++ Builder 6.0中的链接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!
我正在使用C ++ Builder 6.0并对此进行编码:

Hello!
I''m using C++ builder 6.0 and coding this:

<pre lang="xml">//---------------------------------------------------------------------------<br />
#include <vcl.h><br />
#pragma hdrstop<br />
#include <iostream.h><br />
#include <conio.h><br />
#include <string.h><br />
#pragma argsused<br />
class Mystring {  //now with conversion operator<br />
    char *s;<br />
    int size;<br />
    public:<br />
    Mystring(const char *);<br />
    Mystring();<br />
    operator const char * () { return s; } //conversion operator<br />
    //...<br />
};<br />
int main(int argc, char* argv[])<br />
{<br />
    Mystring str("hello world");<br />
    int n = strcmp(str, "Hello");<br />
    cout<<str<<endl;<br />
    getch();<br />
    return 0;<br />
}<br />
</pre><br />


并收到此错误:
[链接器错误]错误:从E:\ _ TPU \ _KI 1 NAM 3 \ _OOP \ LAB5 \ DEBUG_BUILD \ UNIT.OBJ引用的未解决的外部``Mystring :: Mystring(const char *)"
在Visual C ++ 2008中进行编译时,这是相同的错误.
有人可以告诉我这是什么吗?我该如何解决?我的程序正确吗?
非常感谢您!


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!

推荐答案

我不知道您是否发布了完整的代码,但是如果这样做,则仅声明构造函数,而实际上定义它们.尝试将类定义更改为此:


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:


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
    //...
};



您也可以在类外定义构造函数-但我的建议是先阅读一些有关c ++的内容.祝你好运!



You may also define the constructors outside the class - but my suggestion is to do some reading about c++ first. Good luck!!


您可以检查Mystring(const char *)是否已正确定义.
You can check if Mystring(const char *) has defined properly.


这篇关于C ++ Builder 6.0中的链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆