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