[英]Function calling from main() in C++
I have created a class called Login_Class and a header file for the class. 我创建了一个名为Login_Class的类和该类的头文件。 From the main method i am calling a function which is in the Login_Class.
从主要方法中,我正在调用Login_Class中的一个函数。 My problem is , i am getting 2 errors which are not letting me to compile this simple program.
我的问题是,我遇到2个错误,这些错误让我无法编译这个简单的程序。 Since am new to c++ , i am not familiar with the errors.
由于是c ++的新手,所以我不熟悉这些错误。
Here is my login class implementation 这是我的登录类实现
#include<iostream>
#include<stdio.h>
#include "stdafx.h"
#include <string>
#include "Login_Class.h"
using namespace std;
string checkUserType(string userType)
{
if(userType=="Admin")
{
return "Administrator";
}
if(userType=="HR")
{
return "HR";
}
if(userType=="staff")
{
return "staff";
}
}
Here is the header file of the Login_Class 这是Login_Class的头文件
#include "stdafx.h"
#include <string>
#ifndef Login_Class_h
#define Login_Class_h
using namespace std;
class Login_Class
{
public:
string checkUserType(string userType);
};
#endif
Here is my main method code 这是我的主要方法代码
#include "stdafx.h"
#include"Login_Class.h"
#include <string>
#include <iostream>
using namespace std;
int main(){
Login_Class log;
string name=log.checkUserType("Admin"); //calling the function in the login_Class
cout<<name<<endl;
}
Here are the errors which i am getting 这是我遇到的错误
What am i doing wrong here ? 我在这里做错了什么?
Thank you for your time. 感谢您的时间。
Have you tried changing: 您是否尝试过更改:
string checkUserType(string userType)
to 至
string Login_Class::checkUserType(string userType)
I think that include guards
will help. 我认为
include guards
将有所帮助。 In header files create follownig preprocessor block: 在头文件中,创建follownig预处理程序块:
#ifndef _H_LOGIN_CLASS
#define _H_LOGIN_CLASS
////yourcode...
#endif
Include guards prevents during compation from reading the same file more than one time. 包含保护可防止在编译期间多次读取同一文件。 And also boosts compilation speed.
并且也提高了编译速度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.