gpt4 book ai didi

c++ - 错误3错误LNK2019 : unresolved external symbol "public: void __thiscall

转载 作者:太空宇宙 更新时间:2023-11-04 13:23:13 25 4
gpt4 key购买 nike

我一直收到这个错误,它不允许我编译。谁能帮帮我?

这是用户名密码验证器.cpp

#include "UsernamePasswordValidator.h"
#include <cctype>
#include <iostream>
#include <string>

using namespace std;


UsernamePasswordValidator::UsernamePasswordValidator()
{
myUsername = " ";
myPassword = " ";
my_ValidationFailed = true;
}


void UsernamePasswordValidator::setUsername(string username)
{
myUsername = username;
}

void UsernamePasswordValidator::setUsernameViaCString(char *username)
{
myUsername = username;
}

void UsernamePasswordValidator::setPasswordViaCString(char *password)
{
myPassword = password;
}

bool UsernamePasswordValidator::isValid()
{
int upperCase = 0, numCount = 0, lowerCase = 0;

for (int u = 0; u < myUsername.length(); u++)
{

if ( !(isalnum(myUsername.at(u))) )
{
my_ReasonWhyItFailed = "Username must contain both letters and numbers!";
return (my_ValidationFailed = false);
}

if ( isupper(myUsername.at(u)) )
{
upperCase++;
}

if ( islower(myUsername.at(u)) )
{
lowerCase++;
}

if( isdigit(myUsername.at(u)) )
{
numCount++;
}

}

if (myUsername.length() < 8)
{
my_ReasonWhyItFailed = "The username is too short!\n";

return (my_ValidationFailed = false);
}

else if (upperCase == 0)
{
my_ReasonWhyItFailed = "You need at least one Upper case letter.\n";

return (my_ValidationFailed = false);
}

else if (lowerCase == 0)
{
my_ReasonWhyItFailed = "You need at least one lowercase letter.\n";

return (my_ValidationFailed = false);
}

else if (numCount == 0)
{
my_ReasonWhyItFailed = "The username needs a number.\n";

return (my_ValidationFailed = false);
}


upperCase = lowerCase = numCount = 0;


for (int p = 0; p < myPassword.length(); p++)
{

if ( !(isalnum(myPassword.at(p))) )
{
my_ReasonWhyItFailed = "The password needs letters and numbers.";

return (my_ValidationFailed = false);
}

if ( isupper(myPassword.at(p)) )
{
upperCase++;
}

if ( islower(myPassword.at(p)) )
{
lowerCase++;
}

if( isdigit(myPassword.at(p)) )
{
numCount++;
}
}

if (myPassword.length() < 8)
{
my_ReasonWhyItFailed = "password does not contain enough characters.";

my_ValidationFailed = false;
}

else if (upperCase == 0)
{
my_ReasonWhyItFailed = "password does not contain a uppercase value.";

my_ValidationFailed = false;
}

else if (lowerCase == 0)
{
my_ReasonWhyItFailed = "password does not contain a lowercase value.";

my_ValidationFailed = false;
}

else if (numCount == 0)
{
my_ReasonWhyItFailed = "password does not contain a number.";

my_ValidationFailed = false;
}

else if (myPassword.find(myUsername) != string::npos)
{
my_ReasonWhyItFailed = "password cannot contain username.";

my_ValidationFailed = false;
}

return my_ValidationFailed;
}


string UsernamePasswordValidator::reasonForFailure()
{

return my_ReasonWhyItFailed;

}


void UsernamePasswordValidator::reset()
{
myPassword = "";
myUsername = "";
my_ValidationFailed = true;
}

这是我的 UsernamePasswordValidator.h 文件。

#include <iostream>
#include <cctype>
#include <string>

using namespace std;

class UsernamePasswordValidator
{

public:

UsernamePasswordValidator();

void setUsername(string username);
void setPassword(string password);
void reset();
void setUsernameViaCString(char * username);
void setPasswordViaCString(char * password);

string reasonForFailure();

bool isValid();

private:
string myUsername, myPassword, my_ReasonWhyItFailed;
bool my_ValidationFailed;
};

最后,这是我的代码驱动程序。

#include <iostream>
#include <cctype>
#include <string>
#include "UsernamePasswordValidator.h"

using namespace std;

int main()
{
UsernamePasswordValidator upv;

string user, pass;
char * badpassword = "data ";
char * goodpassword = "goodPassword";

cout << "CS52 Username/Password Validator \n";
cout << "\n Username:\n";
getline( cin, user ); // reads a whole line of input

cout << "\n Password: \n";
getline( cin, pass ); // reads a whole line of input

upv.setUsername( user );
upv.setPassword( pass );

if (upv.isValid() )
{
cout << "The Username/Password combination is valid!" << endl;
}
else
{
cout << upv.reasonForFailure( ) << endl;
}

upv.reset( );

upv.setUsername( user );
upv.setPassword( badpassword );

if (upv.isValid() )
{
cout << "The Username/Password combination is valid!" << endl;
}
else
{
cout << upv.reasonForFailure( ) << endl;
}

return 0;
}

最佳答案

您声明了上述方法但未定义。在链接期间,链接器找不到 setPassword 的定义

在 UsernamePasswordValidator.cpp 中添加以下内容:

void UsernamePasswordValidator::setPassword(string password)
{
myPassword = password;
}

关于c++ - 错误3错误LNK2019 : unresolved external symbol "public: void __thiscall,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34235804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com