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 ==========
These are the errors, I tried many of solutions offered here, most being changing linker subsystem and application type, which were both set correctly in the begining.
#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;
}
Sorry for comments on Croatian, I'm sure you can figure out the solution without that :)
Don't declare main as a function template.
Instead, give a proper type to Skud.