尝试在VS中运行C++项目时出现以下错误
我的main.cpp(ATM machine.cpp)
#include <iostream>
#include <fstream>
#include <string>
#include "Account.h"
using namespace std;
class options
{
private:
char user_chose;
int id;
int pass;
public:
void login()
{
// Get credentials
cout << "Please enter your user id: ";
cin >> id;
cout << "Please enter your password: ";
cin >> pass;
}
void quit()
{
cout << "quiting...";
}
void IntroMenu()
{
cout << "Please select an option from the menu below :" << endl;
cout << "l -> Login" << endl;
cout << "c -> Create New Account" << endl;
cout << "q -> Quit" << endl;
cout << "> ";
cin >> user_chose;
switch (user_chose)
{
case ('l'):
case ('L'):
login();
break;
case ('c'):
case ('C'):
Account i;
i.createAccount();
break;
case ('q'):
case ('Q'):
quit();
break;
default:
{
cout << "\n***Invalid option***\n" << endl;
IntroMenu(); //Recall function
}
};
};
};
int main()
{
cout << "Hi!Welcome to the ATM Machine!" << endl;
options start;
start.IntroMenu();
return 0;
}
我的 header (Account.h)
#ifndef ACCOUNT_H_INCLUDED
#define ACCOUNT_H_INCLUDED
class Account
{
public:
void createAccount();
};
#endif
(Account.cpp)
#include "Account.h"
using namespace std;
Account::createAccount();
void Account::createAccount()
{
//Save account on database(txt file)
cout << "\nAccount created successfully\n" << endl;
}
错误1
错误2
提前致谢!
最佳答案
在您的cpp文件中:
#include "Account.h"
using namespace std;
Account::createAccount(); // remove this
void Account::createAccount()
{
cout << "\nAccount created successfully\n" << endl;
}
删除该行之后,您的程序应运行。
编辑
修复之后,它对我来说很好。
你可以尝试移动
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
到
Account.h
并删除其他using namespace std;
,仅在#include <Account.h>
中保留main()
。这提示缺少库,因此也请检查
Account
类文件是否在项目根目录中。如果那不能解决问题,请查看C++ compile error (LNK1120 and LNK2019) with Visual Studio。
关于c++ - C++ MS Visual Studio错误 “referenced in function public: void __thiscall …”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60737164/