类中构造函数的原型不匹配 Hi,所以我对C++非常陌生,并且尝试通过构造函数来生成一个简单的程序,它包含几个变量,然后一些函数来改变这些值。然而我得到

类中构造函数的原型不匹配 Hi,所以我对C++非常陌生,并且尝试通过构造函数来生成一个简单的程序,它包含几个变量,然后一些函数来改变这些值。然而我得到,c++,C++,“User::User(std::string,std::string,std::string,std::string,std::string)”的原型与类“User”中的任何原型都不匹配 main.cpp #include <iostream> #include "User.h" using namespace std; int main() { // Simulates a current existing user User u1("PizzaLover", "ilovepi

“User::User(std::string,std::string,std::string,std::string,std::string)”的原型与类“User”中的任何原型都不匹配

main.cpp

#include <iostream>
#include "User.h"
using namespace std;
int main() {

// Simulates a current existing user
User u1("PizzaLover", "ilovepizza", "pizzaLover@gmail.com", "Tony", "Stark");

// Allows user to change their current username
u1.changeUsername();

// Allows user to change their current password
u1.changePassword();

// Allows user to change their current name
u1.changeName();

// Allows user to view their general account details
u1.printUserDetails();

return 0;
#include <iostream>
#include <stdlib.h>
#include <string>
#include "User.h"
using namespace std;
User::User(string cUsername, string cPassword, string cEmail, string cFirstName, string cLastName) {

username = cUsername;
password = cPassword;
email = cEmail;
firstName = cFirstName;
lastName = cLastName;   
}

cout << endl;
cout << "- - - - - - - - - - - - -" << endl;
cout << "Username:\t" << username << endl;
cout << "Password:\t" << password << endl;
cout << "Email:\t" << email << endl;
cout << "Name:\t" << firstName << " " << lastName << endl; 
cout << "- - - - - - - - - - - - -" << endl;
}

void User::changeUsername() {

string newUserName;

cout << endl;
cout << "Your current username is: " << username << endl;
cout << "Please input your new desired username: ";
cin >> newUserName;

if(username != newUserName) {

    username = newUserName;
    cout << "Your username has been successfully changed." << endl;
    cout << "Your new username is now: " << username << endl;
}

else {
    cout << "Your name is already set to that, next time try a new name." << 
endl;
}
}
#包括
#包括“User.h”
使用名称空间std;
int main(){
//模拟当前现有用户
用户u1(“PizzaLover”、“ilovepizza”pizzaLover@gmail.com“托尼”、“斯塔克”);
//允许用户更改其当前用户名
u1.changeUsername();
//允许用户更改其当前密码
u1.changePassword();
//允许用户更改其当前名称
u1.changeName();
//允许用户查看其常规帐户详细信息
u1.printUserDetails();
返回0;
}

User.h

#ifndef USER_H
#define USER_H
#include <string>
class User {

private:
    std::string username;
    std::string password;
    std::string email;
    std::string firstName;
    std::string lastName;

public:
    User(string cUsername, string cPassword, string cEmail, string cFirstName, string cLastName);
    void printUserDetails(); // this allows the user to view their account details
    void changeUsername(); // this allows the user to change their username
    void changePassword(); // this allows the user to change their password
    void changeEmail(); // this allows the user to change their email
    void changeName(); // this allows the user to change their name
    };
\ifndef用户
#定义用户
#包括
类用户{
私人:
std::字符串用户名;
std::字符串密码;
std::字符串电子邮件;
std::stringfirstname;
std::字符串lastName;
公众:
用户(字符串cUsername、字符串cPassword、字符串cEmail、字符串cFirstName、字符串cPassword NAME);
void printUserDetails();//这允许用户查看其帐户详细信息
void changeUsername();//这允许用户更改其用户名
void changePassword();//这允许用户更改其密码
void changemail();//这允许用户更改他们的电子邮件
void changeName();//这允许用户更改其名称
};
User.cpp

#include <iostream>
#include "User.h"
using namespace std;
int main() {

// Simulates a current existing user
User u1("PizzaLover", "ilovepizza", "pizzaLover@gmail.com", "Tony", "Stark");

// Allows user to change their current username
u1.changeUsername();

// Allows user to change their current password
u1.changePassword();

// Allows user to change their current name
u1.changeName();

// Allows user to view their general account details
u1.printUserDetails();

return 0;
#include <iostream>
#include <stdlib.h>
#include <string>
#include "User.h"
using namespace std;
User::User(string cUsername, string cPassword, string cEmail, string cFirstName, string cLastName) {

username = cUsername;
password = cPassword;
email = cEmail;
firstName = cFirstName;
lastName = cLastName;   
}

cout << endl;
cout << "- - - - - - - - - - - - -" << endl;
cout << "Username:\t" << username << endl;
cout << "Password:\t" << password << endl;
cout << "Email:\t" << email << endl;
cout << "Name:\t" << firstName << " " << lastName << endl; 
cout << "- - - - - - - - - - - - -" << endl;
}

void User::changeUsername() {

string newUserName;

cout << endl;
cout << "Your current username is: " << username << endl;
cout << "Please input your new desired username: ";
cin >> newUserName;

if(username != newUserName) {

    username = newUserName;
    cout << "Your username has been successfully changed." << endl;
    cout << "Your new username is now: " << username << endl;
}

else {
    cout << "Your name is already set to that, next time try a new name." << 
endl;
}
}
#包括
#包括
#包括
#包括“User.h”
使用名称空间std;
User::User(字符串cUsername、字符串cPassword、字符串cEmail、字符串cFirstName、字符串clatname){
用户名=cUsername;
密码=cPassword;
电子邮件=电子邮件;
firstName=cFirstName;
lastName=名称;
}
不能改变:

User(string cUsername, string cPassword, string cEmail, string cFirstName, string cLastName);

User::User(string cUsername, string cPassword, string cEmail, string cFirstName, string cLastName) {

username = cUsername;
password = cPassword;
email = cEmail;
firstName = cFirstName;
lastName = cLastName;   
}
致:


不要使用构造函数体来初始化成员。使用初始化列表。你是否在User.h中包含
?@FrançoisAndrieux是的,它有#ifndef User_h,#define User_h,#include(在修复include和
字符串
vs
std::string
)请提供一个答案,这不会解释错误操作报告,或者OP报告完整错误消息的错误片段此答案不完整。请解释问题的原因或此解决方案是如何解决的。@Jucky Dettinger感谢您解决了此错误。但是现在编译器给出了这个错误。main.cpp:(.text+0xf8):对“User::User(std::string,std::string,std::string,std::string,std::string)”以及每个functions@Surge这就是为什么我们需要一个。下次请求时请这样做。现在您必须定义该函数,否则您将继续得到该错误。顺便说一句,如果人们想因为我的答案给了你正确的答案而否决我的答案,我会毫不在意。