I keep getting this error "_main", referenced from: ..." I'm new to C++ and Xcode can someone explain to me why I'm getting this error and what I need to do to fix it? Thank you
#ifndef bank_h
#define bank_h
#include <iostream>
//using namespace std;
namespace bank_hw
{
class bank
{
public:
int accountNumber;
std::string owner;
std::string newOwner;
double balance;
public:
//default constructor
bank();
bank(int accountNumber, std::string owner, double balance);
//function to deposit
void deposit(double amount);
//function to withdraw
void withdraw(double amount);
//function will display acount info: current owner and current balance
void displayInfo();
//fucntion that will change ownder
void newOwnder(bank& owner, std::string newOwner);
};
}
#endif
Every c++
program need a global main
function to run program.
// bank.hpp
namespace bank_hw
{
class bank
{
public:
int accountNumber;
public:
//default constructor
bank();
};
}
define your class member functions in another another .cpp
file
// bank.cpp
using namespace bank_hw;
bank::bank(): accountNumber( 0 ) {}
and #include
header .hpp
file, where you running your main
function.
#include "bank.hpp"
int main() {
bank_hw::bank b;
return 0;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.