链接错误 LNK1120 和 LNK2019 - "unresolved external symbol _main"

Linking errors LNK1120 and LNK2019 - "unresolved external symbol _main"

1>------ Build started: Project: Seminarski, Configuration: Debug Win32 ------

1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

1>C:\Users-- : fatal error LNK1120: 1 unresolved externals

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

这些是错误,我尝试了这里提供的许多解决方案,大多数是更改链接器子系统和应用程序类型,它们在开始时都设置正确。

#include <iostream>
#include <string>

using namespace std;

template<class T>
class Skup
{
private:
    int n, kap;
    T *p;
public:
    explicit Skup(int N) : kap(N), n(0), p(new T[kap]){}
    Skup(const Skup &x);
    ~Skup(){ delete[] p; }
    Skup &operator = (const Skup &x);
    bool provjera(const T &clan);
    void SetClan(int clan);
    T Getn();
    void sortiranje();
    friend ostream& operator << (ostream& izlaz, Skup x);
};

template<class T>
Skup<T>::Skup(const Skup &x)
{
    n = x.n;
    p = new T[n];
    for (int i = 0; i < n; i++)
        p[i] = x.p[i];
}

template<class T>
Skup<T> &Skup<T>::operator = (const Skup &x)
{
    if (this != &x){
        delete[] p;
        n = x.n;
        p = new T[n];
        for (int i = 0; i < n; i++)
            p[i] = x.p[i];
    }
    return *this;
}

template<class T>
bool Skup<T>::provjera(const T &clan)
{
    
    for (int i = 0; i < n; i++)
    {
        if (p[i] == clan)
            return true;

    }
    return false;
}

template<class T>
void Skup<T>::SetClan(int clan)
{
    if (n == kap)
        throw "Kapacitet popunjen!";

    if (!provjera(clan))
        p[n++] = clan;
}

template<class T>
T Skup<T>::Getn()
{
    return n;
}

template<class T>
void Skup<T>::sortiranje()
{
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n - 1; j++)
        {
            if (p[i]<p[j])
            {
                T tmp = p[i];
                p[i] = p[j];
                p[j] = tmp;
            }
        }
    }
}

template<class T>
ostream& operator << (ostream& izlaz, Skup<T> x)
{   
    izlaz << "{"; 
    for (int i = 0; i < x.n-1; i++)
    {
        izlaz << x.p[i];
        izlaz << ", ";
    } 
    izlaz << x.p[x.n-1] << "}" << endl;
    return izlaz;
    };

template < class T > 
int main()
{
    
    int kapa;
    cout << "Kapacitet:";
    cin >> kapa;
    Skup<T> jedan(kapa);
    
    try{
        int BrEl; // za iznimku, unijeti BrEl > kapa
        cout << "Broj elemenata:";
        cin >> BrEl;
        for (int i = 0; i < BrEl; i++)
        {
            int *cl = new int;
            cout << "Dodaj clana:";
            cin >> *cl;
            if (jedan.provjera(*cl))
            {
                i--;
                cout << "Element vec postoji!" << endl;
            }
            else
                jedan.SetClan(*cl);
            delete cl;
        }
    }
    catch(const char* iznimka){
        cout << endl << iznimka << endl;
    }
    
    jedan.sortiranje();
    cout << jedan;

    system("pause");
    return 0;
}

很抱歉对克罗地亚语发表评论,我相信您可以在没有它的情况下找到解决方案:)

不要将 main 声明为函数模板。

相反,给 Skud 一个合适的类型。