Reputation: 51
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
Upvotes: 1
Views: 326
Reputation: 1180
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;
}
Upvotes: 1