Tiana Chargin
Tiana Chargin

Reputation: 51

C++ Error "_main", referenced from: " Xcode

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

enter image description here

#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

Answers (1)

pvc
pvc

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

Related Questions