d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > I'm New To C++, Everything Really.. > I Can't Find The Solution Via Google.
Add Reply New Topic New Poll
Member
Posts: 3,779
Joined: Apr 13 2008
Gold: 1.38
Dec 30 2013 11:48pm
Error 1 error LNK2019: unresolved external symbol "void __cdecl input(void)" (?input@@YAXXZ) referenced in function _main
There is a total ot 4 unresolved externals. I don't understand what this error is trying to tell me. Could anyone explain it?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Dec 30 2013 11:57pm
You can start by posting the relevant code.
Member
Posts: 3,779
Joined: Apr 13 2008
Gold: 1.38
Dec 31 2013 12:01am
Quote (carteblanche @ Dec 31 2013 05:57am)
You can start by posting the relevant code.


Code
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void input();
void search();
void edit();
void displayALL();
int main()


The main thing is that it doesn't tell me where the error occured like it does with other issues. It just tells me it's there, and I was hoping someone else could tell me what the error actually means. Do you have to introduce (void) itself?

This post was edited by INFlNlTY on Dec 31 2013 12:02am
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Dec 31 2013 12:24am
Code
"void __cdecl input(void)" (?input@@YAXXZ)

The linker tells you exactly where the error is (the exact function signature + its mangled name, should you want to supply it from an another executable).

In your case, you declared that such a function (void input(void)) exists, used it in your main function, but you never defined the function.
Member
Posts: 3,779
Joined: Apr 13 2008
Gold: 1.38
Jan 2 2014 01:29pm
Code
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void input();
void search();
void edit();
void displayALL();
int main()
{
system("cls");
system("title My Database Program");
system("color 0F");
int choice;
cout << "Please enter choice" << endl;
cout << "1. Input new employee" << endl;
cout << "2. Search for an employee by ID number" << endl;
cout << "3. Edit an existing employee's information" << endl;
cout << "4. Display all Employees" << endl;
cout << "5. Exit" << endl;
cin >> choice;

switch (choice){
case 1:
input();
break;
case 2:
search();
break;
case 3:
edit();
break;
case 4:
displayALL();
break;

cin.get();
}

void input();
{
system("cls");
string fname;
string mname;
string lname;
string filename;
double salary;
int empId;
int age;

cout << "Input first name:";
cin >> fname;
cout << "input middle name";
cin >> mname;
cout << "input last name";
cin >> lname;
cout << "input employee age";
cin >> age;
cout << "input salary";
cin >> salary;
cout << "input Id number";
cin >> empId;
string empId2 = to_string(empId);
empId2.append(".txt");

ofstream newemployee(empId2);
newemployee << fname << ' ' << mname << ' ' << lname << ' ' << empId << ' ' << salary << ' ' << age << endl;
newemployee.close();
}
void search();
{

}

void edit();
{

}
void displayALL();
{

}
}


that's the entire code and the errors are:

Code
Error 1 error LNK2019: unresolved external symbol "void __cdecl input(void)" (?input@@YAXXZ) referenced in function _main
Error 2 error LNK2019: unresolved external symbol "void __cdecl search(void)" (?search@@YAXXZ) referenced in function _main
Error 3 error LNK2019: unresolved external symbol "void __cdecl edit(void)" (?edit@@YAXXZ) referenced in function _main
Error 4 error LNK2019: unresolved external symbol "void __cdecl displayALL(void)" (?displayALL@@YAXXZ) referenced in function _main
Error 5 error LNK1120: 4 unresolved externals


This post was edited by INFlNlTY on Jan 2 2014 01:30pm
Member
Posts: 6,192
Joined: Dec 13 2010
Gold: 6,669.99
Jan 2 2014 01:32pm
remove all the ; after the function name

so it would look like
void displayALL()
{

}

and don't put them in your main

You should also put a default in your switch

This post was edited by ShadowFiend on Jan 2 2014 01:37pm
Member
Posts: 3,779
Joined: Apr 13 2008
Gold: 1.38
Jan 2 2014 01:41pm
Quote (ShadowFiend @ Jan 2 2014 07:32pm)
remove all the ; after the function name

so it would look like
void displayALL()
{

}

and don't put them in your main

You should also put a default in your switch


When I do that I get

Code
Error 1 error C2601: 'input' : local function definitions are illegal
Error 2 error C2601: 'search' : local function definitions are illegal
Error 3 error C2601: 'edit' : local function definitions are illegal
Error 4 error C2601: 'displayALL' : local function definitions are illegal



edit: I took the voids out of my main function and it worked; I was just confused. Thanks for your help!

This post was edited by INFlNlTY on Jan 2 2014 01:44pm
Member
Posts: 3,143
Joined: Apr 2 2009
Gold: 175.00
Jan 5 2014 03:52pm
you can't define a function inside another function. This is what your code looks like to me :
Code

//headers

//declarations

int main()
{
...
..
.
void input()
{
...
}
}


Do it like :

Code

//blah
//blah

int main()
{
...
input();
}

void input()
{
...
}
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll