论坛: 编程破解 标题: 请高手给指点下,这个错误怎么改 复制本贴地址    
作者: 清影男孩 [glypk]    论坛用户   登录
#include <iostream>
using namespace std;
typedef unsigned short  USHORT;
typedef unsigned long  ULONG;
short int Divider(
unsigned short  valone,
unsigned short  valtwo);
int main()
{
USHORT one,two;
    short int answer;
cout << "Enter two number.\n Number one: ";
cin >> one;
cout << "Number two: ";
cin >> two;
answer= Divider (one,two);
    if (answer > -1)
cout << "Answer: " << answer;
    else
cout << "Error,can't divide by zero!";
    return 0;
}



Linking...
ex1.obj : error LNK2001: unresolved external symbol "short __cdecl Divider(unsigned short,unsigned short)" (?Divider@@YAFGG@Z)
Debug/example1.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.

example1.exe - 1 error(s), 0 warning(s)
对着书找了半天也不知道哪错了

地主 发表时间: 07-02-11 19:12

回复: jhkdiy [jhkdiy]   版主   登录
代码:

//程序不能只有声明而没有具体实现,
//也就是说你不能骗编译器,明明说有这个函数给它
//但你只是说说,却没有真正给它。
//下面代码在Dev-C++ 4.9.9.2通过。

#include <iostream>
using namespace std;
typedef unsigned short  USHORT;
typedef unsigned long  ULONG;

//这里是声明
short int Divider(unsigned short  valone, unsigned short  valtwo);

int main()
{
    USHORT one,two;
    short int answer;
   
    cout << "Enter two number.\n Number one: ";
    cin >> one;
    cout << "Number two: ";
    cin >> two;
   
    answer= Divider(one,two);
    if (answer > -1)
      cout << "Answer: " << answer;
    else
        cout << "Error,can't divide by zero!";
   
    return 0;
}

//这里是实现
short int Divider(unsigned short  valone, unsigned short  valtwo)
{
      return 0;     
}



B1层 发表时间: 07-02-12 21:07

论坛: 编程破解

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号