您好,所以我对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", "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;
}
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
};
User.cpp
#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;
}
}
答案 0 :(得分:-4)
更改:
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(std::string cUsername, std::string cPassword, std::string cEmail, std::string cFirstName, std::string cLastName);
User::User(std::string cUsername, std::string cPassword, std::string cEmail, std::string cFirstName, std::string cLastName) {
username = cUsername;
password = cPassword;
email = cEmail;
firstName = cFirstName;
lastName = cLastName;
}