我不知道为什么我无法链接这个程序.首先,这是我的头文件,gcd.h:
#ifndef GCD_H
#define GCD_H
/**
* Calculate the greatest common divisor of two integers.
* Note: gcd(0,0) will return 0 and print an error message.
* @param a the first integer
* @param b the second integer
* @return the greatest common divisor of a and b
*/
long gcd(long a, long b);
#endif
Run Code Online (Sandbox Code Playgroud)
这是我的gcd.cpp文件:
#include "gcd.h"
#include <iostream>
using namespace std;
long gcd(long a, long b) {
// if a and b are both zero, print an error and return 0
if ( (a==0) && (b==0) ) {
cerr << "WARNING: gcd called with both arguments equal to zero." << endl;
return 0;
}
// Make sure a and b are both nonnegative
if (a<0) {
a = -a;
}
if (b<0) {
b = -b;
}
// if a is zero, the answer is b
if (a==0) {
return b;
}
// otherwise, we check all the possibilities from 1 to a
long d; // d will hold the answer
for (long t=1; t<=a; t++) {
if ( (a%t==0) && (b&t==0) ) {
d = t;
}
}
return d;
}
Run Code Online (Sandbox Code Playgroud)
主要问题是当我编译时,它返回错误
c:/ mingw/bin /../ lib/gcc/mingw32/4.5.2 /../../../ libmingw32.a(main.o):main.c :(.text + 0xd2):undefined引用`WinMain @ 16'colle2:ld返回1退出状态
我不明白这意味着什么.
请帮忙?
好吧,实际上有人可以修改我的代码以便它正常运行吗?这是最好的选择,因为那时我真的明白我做错了什么.
| 归档时间: |
|
| 查看次数: |
3237 次 |
| 最近记录: |