Home > other >  undefined reference to `Account::set_balance(double)' ----What does it mean? [duplicate]
undefined reference to `Account::set_balance(double)' ----What does it mean? [duplicate]

Time:09-17

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....................................................................................................................

CodePudding user response:

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
  • Related