嗨,大家好我是OOP和C++的新手,所以請耐心等待。'newacc'不是一個類或名稱空間
我想定義一個類,它的功能,然後使用它們。我會顯示我到目前爲止以及我遇到錯誤的位置。
在一個名爲 「account.h」 我有:
#include <iostream>
#include <string>
using namespace std;
class Account{
string fname;
string lname;
string sinnum;
string accttype;
int numtrans;
double balance;
public:
Account(string,string,string,string);
double DepositAmt(double);
double WithdrawAmt(double);
void PrintStatement();
void getFinalBalance();
};
在一個名爲 「account.cpp」 我有:
Account::Account(string firstname, string lastname, string sinnumber, string acc
{
fname = firstname;
lname = lastname;
sinnum = sinnumber;
accttype = accounttype;
numtrans = 0;
balance = 0;
}
double Account::DepositAmt(double deposit)
{
balance = balance + deposit;
return balance;
}
double Account::WithdrawAmt(double withdraw)
{
balance = balance - withdraw;
return balance;
}
void Account::PrintStatement()
{
cout << "First Name: " << fname << endl;
cout << "Last Name: " << lname << endl;
cout << "SIN: " << sinnum << endl;
cout << "Account Type: " << accttype << endl;
cout << "Total Transactions: " << numtrans << endl;
cout << "Final balance: $" << balance << endl;
}
void Account::getFinalBalance()
{
cout << "Your Final balance is: $" << balance << endl;
}
最後,在我的最後一個文件名爲「 ass2012.cpp「我有:
#include "account.h"
#include "account.cpp"
int main()
{
string fname, lname, sinnum, accttype;
int tempaccttype;
cout << "\nPlease enter your last name: " << endl;
cin >> lname;
cout << "\nPlease enter your SIN number: " << endl;
cin >> sinnum;
cout << "\nPlease choose your account type: "<< endl;
cout << "1: Checking" << endl;
cout << "2: Savings" << endl;
cin >> tempaccttype;
if (tempaccttype == 1)
{
accttype = "Checking";
}
else
{
accttype = "Savings";
}
Account newacc (fname, lname, sinnum, accttype); // HERE IS WHERE I GET THE ERROR
newacc::getFinalStatement();
return 0;
}
你能告訴我我做錯了什麼!
編輯:謝謝納文!它總是讓我感覺到這些牆壁的小事情。