我是C ++的新手,我似乎总是得到这个错误。这真是令人沮丧,因为它完全阻碍了我在此任务中的制作。我有点理解错误的原理,但函数是在调用之前定义的,所以我不明白。
我收到以下错误:
Error 3 error LNK2019: unresolved external symbol "public: void __thiscall Driver::mainMenu(void)" (?mainMenu@Driver@@QAEXXZ) referenced in function "public: void __thiscall Driver::customerMenu(class std::vector<class Customer,class std::allocator<class Customer> >)" (?customerMenu@Driver@@QAEXV?$vector@VCustomer@@V?$allocator@VCustomer@@@std@@@std@@@Z) H:\Uni\Year 2\FPC++\Tutorial 4\SimpleSavings\SimpleSavings\Main.obj Assignment
从这段代码:
#include "Account.h"
#include "Customer.h"
#include "Driver.h"
#include "JuniorCurrentAccount.h"
#include "CorporateSavingsAccount.h"
#include "StudentSavingsAccount.h"
#include "CurrentAccount.h"
#include "Transaction.h"
#include <stdlib.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
static int customerIndex = 0;
static int accountIndex = 0;
static int accNum = 1;
static Driver d;
void mainMenu() {
while (true)
{
vector<Customer> customers;
if (customers.size() == 0)
{
cout << "________________________" << endl;
cout << "//CURRENT CUSTOMER: NO CUSTOMERS" << endl;
cout << "//CURRENT ACCOUNT: NO ACCOUNTS" << endl;
} else if (customers.at(customerIndex).getAccounts().size() == 0)
{
cout << "________________________" << endl;
cout << "//CURRENT CUSTOMER: " << customers.at(customerIndex).getName() << endl;
cout << "//CURRENT ACCOUNT: NO ACCOUNTS" << endl;
} else
{
cout << "________________________" << endl;
cout << "//CURRENT CUSTOMER: " << customers.at(customerIndex).getName() << endl;
cout << "//CURRENT ACCOUNT: " << customers.at(customerIndex).getAccounts().at(accountIndex).getAccountNum() << " (" << customers.at(customerIndex).getAccounts().at(accountIndex).getType() << ")" << endl;
}
cout << "//MAIN MENU " << endl;
cout << "||Customers (1) " << endl;
cout << "||Accounts (2) " << endl;
cout << "||Transactions (3) " << endl;
cout << "||";
int mainMenuChoice;
cin >> mainMenuChoice;
if (mainMenuChoice == 1)
{
d.customerMenu(customers);
}
int c;
cin >> c;
}
}
//tier 1
void Driver::customerMenu(vector<Customer> customers)
{
cout << "________________________" << endl;
cout << "//CUSTOMER MENU" << endl;
cout << "||Create new customer (1) " << endl;
cout << "||Select a customer (2) " << endl;
cout << "||List all customers (3) " << endl;
cout << "||Delete a customer (4) " << endl;
cout << "||Back (5)" << endl;
cout << "||";
int customerMenuChoice;
cin >> customerMenuChoice;
if (customerMenuChoice == 1)
{
createCustomer(customers);
} else if (customerMenuChoice == 2)
{
if (customers.size() == 0)
{
{
cout << "________________________" << endl;
cout << "//CUSTOMER SELECTIONS" << endl;
cout << "||There are no customers! " << endl;
customerMenu(customers);
}
} else
{
selectCustomer(customers);
}
} else if (customerMenuChoice == 3)
{
listCustomers(customers);
} else if (customerMenuChoice == 4)
{
cout << "||TBI"<< endl;
} else if (customerMenuChoice == 5)
{
mainMenu();
}
}
答案 0 :(得分:3)
未解决的符号是公开的:void __thiscall Driver::mainMenu(void)
而不是public: void mainMenu(void)
。因此编译器期望mainMenu
类中的Driver
函数。您对mainMenu
的定义不在课堂上。它是全球性的。您可能已将其声明为标头中的成员函数。这是编译器正在寻找的实现。