简体   繁体   中英

Function calling from main() in C++

I have created a class called Login_Class and a header file for the class. From the main method i am calling a function which is in the Login_Class. My problem is , i am getting 2 errors which are not letting me to compile this simple program. Since am new to c++ , i am not familiar with the errors.

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

#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. In header files create follownig preprocessor block:

#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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM