0

Account.h file

#ifndef ACCOUNT_H
#define ACCOUNT_H

class Account
{
private:
    //attributes
    double balance;
public:
    //methods
    void set_balance(double bal);
    double get_balance();
};

#endif

Account.cpp file

#include "Account.h"
void Account::set_balance(double bal){
    balance=bal;
}
double Account::get_balance(){
    return balance;
}

main.cpp file

#include<iostream>
#include"Account.h"

int main(){
    Account frank_account;
    frank_account.set_balance(200.00);
    double showBalance=frank_account.get_balance();
    return 0;
}

error

C:\Users\Dell\AppData\Local\Temp\ccZOi0ua.o: In function `main':
F:/OPP/opp10/main.cpp:6: undefined reference to `Account::set_balance(double)'
F:/OPP/opp10/main.cpp:7: undefined reference to `Account::get_balance()'
collect2.exe: error: ld returned 1 exit status

Build finished with error(s).
The terminal process terminated with exit code: -1.

Please explain the error message and provide the solution. Thank You....................................................................................................................

  • You generally have two main steps to build a program : compilation of sources into objects, then linking of these objects into an executable. Your error message suggests that you did not provide all the objects to the linker, or in the wrong order. What is your command that generated this error ? – SR_ Sep 09 '21 at 07:28

1 Answers1

0

How did you compile these two files? This error suggests that the "Account.cpp" is not compiled or linked by you. Try this:

gcc Account.cpp main.cpp
Mike Dog
  • 74
  • 1
  • 6