C++问题LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main

来源:百度知道 编辑:UC知道 时间:2024/09/19 16:13:03
请问:下面程序为什么在连接时有错,而在不用类模板时又没有错
另外:operator() 、operator== 在程序中是究竟是怎样被调用的
#include <iostream>
#include <set>
using namespace std;

template <class T>
class RuntimeCmp {
public:
enum cmp_mode {normal, reverse};
private:
cmp_mode mode;
public:
//constructor for sorting criterion
//-default criterion uses value normal
RuntimeCmp (cmp_mode m=normal) : mode(m) {
}
//comparision of elements
bool operator() (const T& t1, const T& t2) const {
return mode == normal ? t1 < t2 : t2 < t1;
}
//comparision of sorting criteria
bool operator== (const RuntimeCmp& rc) {
return mode == rc.mode;
}
};

//type of a set that uses this sorting criterion

typedef set<int,RuntimeCmp<int> > IntSet;

void fill (IntSet& Set)
{
//fill ins

没写main函数呗

根据你的出错信息来看,要么你没有main,要么你有多余的main
这些运算符的调用和函数是一样的
他们有参数,也有返回类型,当然并不是所有的都是这样,如 operator type()就没有返回类型,其实type就是,调用我也不太清楚.如class operator+(),如是全局的则()内的一个是左操作数,一个是右操作数 ,class代表返回值,operator==类似