使用類和模板進行類的簡單分配,已經在這裏搜索,沒有解決方案似乎可以解決問題。當我嘗試編譯時,出現:VS2010:致命錯誤LNK1120:1個未解決的外部事件。使用模板
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup 1>c:\users\leanne\documents\visual studio 2010\Projects\PartC\Debug\PartC.exe : fatal error LNK1120: 1 unresolved externals
有一個使用空項目的控制檯項目。任何人都可以幫我找到問題嗎? 這裏是我的代碼:
#include <iostream>
using namespace std;
template<typename ItemType>
class Vec3
{
ItemType x, y ,z;
public:
Vec3<ItemType>(){x=0;y=0;z=0;}
Vec3<ItemType>(const Vec3<ItemType>& other);
Vec3<ItemType> operator+(Vec3<ItemType>);
Vec3<ItemType> operator-(Vec3<ItemType>);
bool operator==(Vec3<ItemType> other);
Vec3<ItemType> operator=(Vec3<ItemType>);
~Vec3<ItemType>(){;}
};
template<typename ItemType>
Vec3<ItemType> Vec3<ItemType>::operator+(Vec3<ItemType> other)
{
Vec3 temp;
temp.x = x + other.x;
temp.y = y + other.y;
temp.z = z + other.z;
return temp;
}
template<typename ItemType>
bool Vec3<ItemType>::operator==(Vec3<ItemType> other)
{
if(x != other.x)
return false;
if(y != other.y)
return false;
if(z != other.z)
return false;
return true;
}
template<typename ItemType>
Vec3<ItemType> Vec3<ItemType>::operator-(Vec3<ItemType> other)
{
Vec3 temp;
temp.x = x - other.x;
temp.y = y - other.y;
temp.z = z - other.z;
return temp;
}
template<typename ItemType>
Vec3<ItemType> Vec3<ItemType>::operator=(Vec3<ItemType> other)
{
x = other.x;
y = other.y;
z = other.z;
return *this;
}
template<typename ItemType>
Vec3<ItemType>::Vec3(const Vec3<ItemType>& other)
{
x = other.x;
y = other.y;
z= other.z;
}
template<typename ItemType>
int main()
{
Vec3<int> v1;
Vec3<int> v2(v1);
Vec3<double> v3 = v2;
v3 = v1+v2;
v3 = v1-v2;
if(v1==v2)
{
return 0;
}
return 0;
}
*問題*是什麼? – 2013-04-08 22:01:32
即時獲取LNK 1120無法解析的外部錯誤,所以它不會編譯 – 2013-04-08 22:03:29
什麼是*完整*錯誤?你遺漏了描述錯誤的部分。 – 2013-04-08 22:04:14