功能已经具有字符串变量的主体和重新定义

function already has a body and redefinition of string variable

本文关键字:新定义 定义 主体 变量 字符串 功能      更新时间:2023-10-16

错误:错误消息

mainfun.cpp:

#include <iostream>
#include <string>
#include "userCheckFunH.h"
using namespace std;
int yesNo;
string passName;
string userName;
string userRetrieve()
{
    if (userName == "")
    {
        cin >> userName;
    }
    else
    {
        if (userName == "devin772" || userName == "guestacc")
        {
            yesNo = 1;
        }
        else
        {
            yesNo = 0;
        }
    }
    return userName;
}
int userCheck()
{
    return yesNo;
}

int main()
{
    do
    {
        string userN;
        system("cls");
        // ui
        cout << "      DH DB     " << endl;
        cout << "x----------------x" << endl;
        //username 
        cout << "username: " << endl;
        cout << "> ";
        // fun call
        userRetrieve();
        int continueP = userCheck();
        cout << "" << endl;
        // password
        if (continueP = 1 && userRetrieve() == "devin772")
        {
            cout << "password:" << endl;
            cout << "> ";
            cin >> passName;
            if (passName == "12qwaszx")
            {
                cout << "" << endl;
                system("pause");
                system("cls");
                // run program
                dataBaseRunP("admin");
                npOpen();
                cout << "" << endl;
                system("pause");
                return 0;
            }
        }
        else if (continueP = 1 && userRetrieve() == "guestacc")
        {
            cout << "password:" << endl;
            cout << "> ";
            cin >> passName;
            if (passName == "guestguest")
            {
                cout << "" << endl;
                system("pause");
                system("cls");
                // run program
                dataBaseRunP("regUser");
                npOpen();
                cout << "" << endl;
                system("pause");
                return 0;
            }
        }
        else
        {
            cout << "Invalid username." << endl;
            cout << "" << endl;
            system("pause");
            userRetrieve() = "";
            userName = "";
            yesNo = 0;
            passName = "";
        }
    } while (true);
    system("pause");
}

nextfun.cpp:

#include <iostream>
#include "userCheckFunH.h"
using namespace std;
string userLevel;
int dataBaseRunP(string authLevel)
{
    string fileName;
    if (authLevel == "regUser")
    {
        fileName = "user.txt";
        userLevel = fileName;
    }
    else if (authLevel == "admin")
    {
        fileName = "admin.txt";
        userLevel = fileName;
    }
    else
    {
        cout << "ERROR - user level not found." << endl;
        system("pause");
        exit(EXIT_FAILURE);
        return 0;
    }
    exit(EXIT_SUCCESS);
    return 0;
}
void npOpen()
{
    string fileNpName;
    fileNpName = userLevel;
    fileNpName = "notepad "" + fileNpName + """;
    system(fileNpName.c_str());
}

userCheckfunh.h:

#ifndef USERCHECKFUN_H
#define USERCHECKFUN_H
#include "nextFun.cpp"
 int dataBaseRunP();
 void npOpen();
#endif 

我正在尝试制作一个基本程序,该程序允许您在基本的C 程序中通过Windows打开文件。继续遇到此错误。尝试了不同的标头电具,可变名称,功能名称,文件名。我还删除了nextfun.cpp,并且程序运行良好。我无法克服此错误,请提供帮助。谢谢!:)

包括

在UserCheckfunh.h中使用的CPP文件是非常不寻常的
#include "nextFun.cpp"

您的nextfun.cpp文件包含此标题:

#include "userCheckFunH.h"

由于您的CPP文件没有include guard(很好),因此您两次获得CPP文件中的功能。

不在标题中包含CPP文件。