c++ - VS2010: fatal error LNK1120: 1 unresolved externals . Working with templates -
have simple assignment classes , templates class, have searched on here , no solutions seem fix issue. when try compile, comes up:
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
have console project using empty project. can me find issue? here code:
#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; }
your getting error because made main
template:
template<typename itemtype> int main()
please remove template<typename itemtype>
. main
not allowed template.
once remove that, errors on vec3<double> v3 = v2;
because v2
vec3<int>
, cannot converted vec3<double>
.
Comments
Post a Comment