你好派对的人我每次尝试编译时都会从编译器中得到这个错误这个错误发生在我的许多其他代码有任何想法吗?
错误3错误LNK2019:未解析的外部符号“void __cdecl viewaddressbook(void)”(?viewaddressbook @@ YAXXZ)在函数“void __cdecl menu(void)”中引用(?menu @@ YAXXZ)
错误2错误LNK2019:未解析的外部符号“void __cdecl removeentry(void)”(?removeentry @@ YAXXZ)在函数“void __cdecl menu(void)”中引用(?menu @@ YAXXZ)
#include "stdafx.h"
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void menu();
void addentry();
void removeentry();
void viewaddressbook();
map<string, string>names;
int main()
{
menu();
return 0;
}
void menu()
{
int choice;
cout << "1.View Address Book \n2. Add Entry \n3. Remove Entry" << endl;
cin >> choice;
switch (choice)
{
case 1:
viewaddressbook();
break;
case 2:
addentry();
break;
case 3:
removeentry();
break;
}
}
void addentry()
{
string email;
string firstlast;
cout << "Enter the persons email\n" << endl;
cin >> email;
cout << "Enter the person's first and last name";
cin >> firstlast;
names[email] = firstlast;
cout << firstlast << " was added with the email of " << email << endl;
cin.get();
cin.ignore();
}
void removeentry(map<string,string> names)
{
string shrink;
int choice;
string nametoremove;
if (names.empty())
{
cout << "You have no one to remove\n";
menu();
}
else
{
cout << "Who do you want to remove ?" << endl;
cin >> nametoremove;
map<string, string>::iterator itr = names.find(nametoremove);
if (itr == names.end())
{
cout << "Sorry no one by the name of" << nametoremove;
}
else if (itr != names.end())
{
cout << "You sure you want to remove " << nametoremove << "\n\n1.Yes\n2.No" << endl;
cin >> choice;
switch (choice)
{
case 1:
names.erase(itr);
cout << nametoremove << " was removed";
menu();
break;
case 2:
menu();
break;
}
}
}
}
void viewaddressbook(map<string,string> names)
{
for (map<string, string>::iterator itr = names.begin(); itr != names.end();)
{
cout << itr->first << "|" << itr->second;
}
cin.get();
cin.ignore();
menu();
}
2 回答
你的功能
没有定义 . 而是你定义的
所以链接器无法解析调用
您将文件顶部的函数声明为:
但您使用的定义不匹配:
更改顶部的声明以匹配函数定义以修复错误消息: