我搜索了网站,有关于默认构造函数或使用#pragma的答案。但我在我的视觉工作室使用#pragma,我试图调试,但任何这些方法都没有用。请告诉我哪里弄错了。谢谢
这是我的主要内容,
#include "stdafx.h"
#include<iostream>
#include "Login.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
Login log;
log.loginMenu();
std::cin.get();
return 0;
}
login.h如下, #pragma一次
class Login
{
public:
void loginMenu();
};
和Login.cpp文件,
#include "stdafx.h"
#include "Login.h"
#include<iostream>
#include<string>
using namespace std;
void loginMenu()
{
int userType;
do{
cout << "Select 1 for STAFF" << endl;
cout << "Select 2 for HR MANAGER" << endl;
cout << "Select 3 for ADMINISTRATOR" << endl;
cout << "Please select your usertype";
cin >> userType;
switch(userType){
case 1:
cout << "You have selected STAFF";
break;
case 2:
cout << "You have selected HR MANAGER";
break;
case 3:
cout << "You have selected ADMINISTRATOR";
break;
default:
cout << "Please make your choice by selecting from 1-3";
}
}while(userType==1,userType==2,userType==3);
}
这是我创建的一个简单程序,用于演示“在单独的文件中使用类。
答案 0 :(得分:4)
您已声明并正在调用函数Login::loginMenu
- 类Login
的成员函数 - 但您尚未实现它。您已经实现了一个函数::loginMenu
- 一个非成员独立函数 - 但您没有调用它。
成功
void Login::loginMenu() {...}