Pergunta

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

enter image description here

What am i doing wrong here ?

Thank you for your time.

Foi útil?

Solução

Have you tried changing:

string checkUserType(string userType)

to

string Login_Class::checkUserType(string userType)

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top