所以我只是编写一个简单的c ++程序,我在运行程序时遇到了一些问题。我可以构建我的make文件,但是当我尝试运行testfile时,它会给我一个"collect2.exe: error: ld returned 1 exit status"
错误,"undefined reference to Account::Account(int, double, double)"
以及我的所有方法。我附上了我的.h文件的图片,以及下面的.cpp文件。
测试文件是这样的:
#include <iostream>
#include <string>
#include <iomanip>
#include "Account.h"
using namespace std;
int main(){
Account account1(1122, 20000, 4.5);
account1.withdraw(2500);
account1.deposit(3000);
cout<<"Account Information"<<endl
<<"ID: " << account1.getID()<<endl
<<"Balance: " << account1.getBalance()<<endl
<<"Monthly Interest Rate: " << account1.getMonthlyInterestRate()<< endl;
return 0;
}
制作档案:
TestAccount: TestAccount.o Account.o
g++ TestAccount.o Account.o -o TestAccount
TestAccount.o: TestAccount.cpp Account.h
g++ -c TestAccount.cpp
Account.o: Account.cpp Account.h
g++ -c Account.cpp