0

Have a simple assignment with classes and templates for class, have searched on here and no solutions seem to fix the issue. When I try to compile, this 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 a console project using an empty project. Can anyone help me find the issue? Here is my 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;
 }  
Drew Dormann
  • 59,987
  • 13
  • 123
  • 180
Wade Guest
  • 65
  • 1
  • 1
  • 7
  • im getting a LNK 1120 unresolved external error so it won't compile – Wade Guest Apr 08 '13 at 22:03
  • What is the *complete* error? You left out the part that describes what's wrong. – Drew Dormann Apr 08 '13 at 22:04
  • Can you be more specific? What is the symbol? – Mark Ransom Apr 08 '13 at 22:04
  • try to compile, this 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 – Wade Guest Apr 08 '13 at 22:05
  • "unresolved external symbol _main" means that a non-templated function named `main` is missing. – Drew Dormann Apr 08 '13 at 22:05

1 Answers1

1

Your getting the error because you made main a template:

template<typename ItemType>
int main()

Please remove the template<typename ItemType>. main is not allowed to be a template.

Once you remove that, you will get errors on Vec3<double> v3 = v2; because v2 is a Vec3<int> and cannot be converted to a Vec3<double>.

Jesse Good
  • 50,901
  • 14
  • 124
  • 166