简体   繁体   中英

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

在此处输入图片说明

#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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM