문제

I'm a newbie to C++, and I seem to be getting this error a whole lot. It's really frustrating as it's totally hindering my production on this assignment. I kinda understand the principle of the error, but the function is defined before it is called, so I don't understand that.

I'm getting the following error:

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

From this code:

#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();
}
}
도움이 되었습니까?

해결책

The unresolved symbol is public: void __thiscall Driver::mainMenu(void) not public: void mainMenu(void). So the compiler expects mainMenu function in Driver class. Your definition of mainMenu is not in the class. It is global. You probably have it declared as a member function in the header. It is its implementation the compiler is looking for.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top