c++ - C++错误 “_main”,引用自:“Xcode

标签 c++ xcode class object

我不断收到此错误“_main”,引用自:...”我是C++的新手,Xcode可以向我解释为什么我收到此错误,以及需要怎么做才能解决它?
谢谢
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

最佳答案

每个c++程序都需要一个全局main函数来运行程序。

// bank.hpp

namespace bank_hw
{
    class bank
    {
        public:
            int accountNumber;
    
        public:
            //default constructor
            bank();
    
    };
}
在另一个.cpp文件中定义您的类成员函数
// bank.cpp


using namespace bank_hw;

bank::bank(): accountNumber( 0 ) {}
#include header .hpp文件,在其中运行main函数。
#include "bank.hpp"

int main() {
    
    bank_hw::bank b;
    
    return 0;
}

关于c++ - C++错误 “_main”,引用自:“Xcode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63626421/

相关文章:

c++ - 指向成员的指针作为模板参数

c++ - 如何修复 cv::SVMParams 的丢弃限定符 [-fpermissive]?

c++ - fatal error : yaml-cpp/yaml. h:没有那个文件或目录

ios - 使用cordova-ios@4.0和Xcode 7.2.1进行Cordova 6.0.0 iOS本地化

swift - 归档项目卡了几个小时

iphone - xCode/在类中声明静态方法

jquery fullcalendar 与更新事件无法更新类

c++ - "inverse"通过丢弃c++中的参数进行绑定(bind)

javascript - 我应该如何处理 JavaScript 中对象构造函数的无效输入

ios - 在 Swift 中将对象从一个类移动到另一个类