Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++: Undefined Reference / Linkage Error? I\'m using three files - main.cpp, fun

ID: 3803836 • Letter: C

Question

C++: Undefined Reference / Linkage Error?

I'm using three files - main.cpp, function_file.cpp, header_file.h. When including the header file in each of the .cpp files, I'm getting an error at each of the function calls in main that...

||=== Build: Debug in PMProject1 (compiler: GNU GCC Compiler) ===|
objDebugmain.o||In function `main':|
C:UsersxDesktopPM Project 1main.cpp|39|undefined reference to `void makeAccount(std::vector >&)'|
C:UsersxDesktopPM Project 1main.cpp|43|undefined reference to `void PrintAllAccount(std::vector >&)'|
C:UsersxDesktopPM Project 1main.cpp|47|undefined reference to `void depositAccount(std::vector >&)'|
C:UsersxDesktopPM Project 1main.cpp|51|undefined reference to `void withdrawAccount(std::vector >&)'|
C:UsersxDesktopPM Project 1main.cpp|55|undefined reference to `void printAccount(std::vector >&)'|
C:UsersxDesktopPM Project 1main.cpp|59|undefined reference to `void deleteAccount(std::vector >&)'|
||error: ld returned 1 exit status|
||=== Build failed: 7 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

I'm using code::blocks and all files are correctly added to the project.

Here are the relevant files:

Main:

#include "header_file.h"
#include
#include
#include
#include

using namespace std;


int main() {
// declare list of account here. The size of the list is not fixed.

struct Account{
int accountNumber;
string lastName;
string firstName;
double accountBalance;
};

vector bankAccounts;
Account a;

int input = 0;
int *inputPtr = &input;
while(input != 7)
{
menu(inputPtr);
// run loop to continue program until terminated by user

switch (input)
{ //cases: call functions to perform tasks
case 1:
makeAccount(bankAccounts);
break;

case 2:
PrintAllAccount(bankAccounts);
break;

case 3:
depositAccount(bankAccounts);
break;

case 4:
withdrawAccount(bankAccounts);
break;

case 5:
printAccount(bankAccounts);
break;

case 6:
deleteAccount(bankAccounts);
           break;

           case 7:
return 0;
           break;

           default:
cout << "Invalid Input. Choose a number from 1 through 7." << endl << endl;
}
}
return 0;
}

-------

beginning of the function_file.cpp:

// function_file.cpp
#include
#include
#include
#include
#include
#include
#include
#include "header_file.h"

int index;
using namespace std;

void menu(int *num)
{
int select = 0;
cout << "Welcome to Made_up Banking. Select options below:" << endl;
cout << " 1. Make new account." << " 2. Display all accounts."
<< " 3. Deposit to an account." << " 4. Withdraw from an account."
<< " 5. Print account." << " 6. Delete an Account." << " 7. Quit." << endl;
cout << "Selection: ";
cin >> select;
*num = select;
}

template
void makeAccount(vector & newA)
{

typeStruct newAccount;

   srand(time(0));
newAccount.accountNumber = (rand() % 9999) + 1;
   cout << " Creating bank account number: " << newAccount.accountNumber << endl;

cout << "Enter first name:" << endl;
cin >> newAccount.firstName;

cout << endl << "Enter last name:" << endl;
cin >> newAccount.lastName;

cout << endl << "Enter starting balance:" << endl;
cin >> newAccount.accountBalance;

newA.push_back(newAccount);
cout << "Your Account has been created! " << endl;

//sortAccounts();

} //more functions below in this file

-------

header_file:

// header_file.h

#ifndef H_GLOBALS
#define H_GLOABLS


#include
#include
#include
#include
#include

using namespace std;


void menu(int*);

template
void makeAccount(vector &);

template
void makeAccount(vector &);

template
void printAccount(vector &);

template
void PrintAllAccount(vector &);

template
void depositAccount(vector &);

template
void withdrawAccount(vector &);

template
void sortAccounts(vector &); // sort the accounts using the account numbers

template
void deleteAccount(vector &);

template
int validInput(int, vector &);

#endif

Explanation / Answer

your code dont hv missing.try this to run it in command prompt .chage your directory to your folder then type your project name then execute it.

or else

change your properties of your project to build targets what type do you have ,GUI appliction ?console application ?run your application in debbugger step by step u may get where u wil fail.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote