Compiles with 0 error but when I run it. 2 Errors appear
Error:
--------------------Configuration: nc - Win32 Debug--------------------
Compiling...
cv.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/nc.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
nc.exe - 2 error(s), 0 warning(s)
|
I'm Inputing data of an object from user and then inserting it in the link list.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include <iostream>
//#include <fstream>
using namespace std;
#define LEN 100
////////////////////////////////////////////////////////////////////////////////////////////////////
class employee{
private:
char name[LEN];
unsigned long number;
public:
friend istream& operator >> (istream& s, employee& e){
cout << "Name: "; s.getline(e.name,LEN,'\n');
cout << "Number: "; s >> e.number;
return s;
}
friend ostream& operator << (ostream& s, employee& e){
cout << "Name: " << e.name << endl << "Number: " << e.number << endl;
return s;
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
template <class T>
struct link{
T data;
link* next;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
template <class T>
class linklist{
private:
link<T>* first;
public:
linklist()
{ first = NULL; }
void addItem(T d);
void print();
};
//--------------------------------------------------------------------------------------------------
template <class T>
void linklist<T>::addItem(T object_of_Employee){
link<T>* temp = new link<T>;
temp->data = object_of_Employee;
temp->next = first;
first = temp;
}
//``````````````````````````````````````````````````````````````````````````````````````````````````
template <class T>
void linklist<T>::print(){
link*<T> p = first;
while (p!=NULL){
cout << p->data << endl << "------------------------------------------------------" << endl;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//**************************************************************************************************
template <class T>
int main(){
linklist<link> ll;
employee newEmp;
char ans;
do{
cin >> newEmp;
ll.addItem(newEmp);
cout << "Another (y/n): "; cin >> ans;
}while (ans != 'n' && ans == 'y');
ll.print();
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
|
Last edited on
Function main may not be a template function. So remove statement with template before main
template <class T>
int main(){
Topic archived. No new replies allowed.