I don't understand why I am getting the following error in my main.cpp file: undefined reference to 'BankDetails::BankDetails()' undefined reference to 'BankDetails::Setname(std::string)' etc etc
I have checked everything and even some references online but they don't explain where I am going wrong. Your help is much appreciated.
BankDetails.h:
#ifndef BANKDETAILS_H
#define BANKDETAILS_H
#include <iostream>
#include <string>
using namespace std;
class BankDetails
{
public:
BankDetails();
void Setname(string n);
void Setaccnr(string accNr);
void Settype(string accType);
void Setbranch(string code);
void SetinterestRate(double val);
string Getname() const;
string Getaccnr()const;
string Gettype()const;
string Getbranch()const;
double GetinterestRate()const;
private:
string name;
string accnr;
string type;
string branch;
double interestRate;
};
#endif // BANKDETAILS_H
BankDetails.cpp:
#include "BankDetails.h"
#include <string>
#include <iostream>
using namespace std;
BankDetails::BankDetails()
{
name = " ";
accnr = " ";
type = " ";
branch = " ";
interestRate = 0;
//ctor
}
void BankDetails::Setname(string n)
{
name = n;
}
void BankDetails::Setaccnr(string accNr)
{
accnr = accNr;
}
void BankDetails::Settype(string accType)
{
type = accType;
}
void BankDetails::Setbranch(string code)
{
branch = code;
}
void BankDetails::SetinterestRate(double val)
{
interestRate = val;
}
string BankDetails::Getname()const
{
return name;
}
string BankDetails::Getaccnr()const
{
return accnr;
}
string BankDetails::Getbranch()const
{
return branch;
}
string BankDetails::Gettype()const
{
return type;
}
double BankDetails::GetinterestRate() const
{
return interestRate;
}
main.cpp:
#include <iostream>
#include <string>
#include "BankDetails.h"
using namespace std;
//Main function
int main()
{
BankDetails bankDetails;
string n, accNr, accType, code;
double val;
cout << "Enter account holder name: " ;
getline(cin, n);
bankDetails.Setname(n);
cout << "Enter account number: " ;
getline(cin, accNr);
bankDetails.Setaccnr(accNr);
cout << "Enter account type: " ;
getline(cin, accType);
bankDetails.Settype(accType);
cout << "Enter branch code: " ;
getline(cin, code);
bankDetails.Setbranch(code);
cout << "Enter interest rate: " ;
cin >> val;
bankDetails.SetinterestRate(val);
//Display bank details
cout <<"\nAccount holder's name: " << bankDetails.Getname() << endl;
cout <<"Account number: " << bankDetails.Getaccnr() << endl;
cout <<"Type of account: " << bankDetails.Gettype() << endl;
cout <<"Branch Code: " << bankDetails.Getbranch() << endl;
cout <<"Interest rate: " << bankDetails.GetinterestRate() << endl;
return 0;
}