如何解决C ++错误“ _main”,引用自:“ Xcode
我不断收到此错误“ _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
头文件.hpp
,在其中运行main
函数。
#include "bank.hpp"
int main() {
bank_hw::bank b;
return 0;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。