#ifndef LibraryUser_h
#define LibraryUser_h
#include <string>
using namespace std;
class LibraryUser {
private:
std::string name;
std::string email;
int idnumber;
public:
LibraryUser(string name, string email, int idnumber);
LibraryUser();
void addnewuser();
string getName();
string getEmail();
int getIdnumber();
void setName(string name);
void setEmail(string email);
void setIdnumber(int idnumber);
};
#endif
字符串
美共
#include "LibraryUser.h"
#include <string>
#include <iostream>
using namespace std;
LibraryUser(string name, string email, int idnumber) {
this->name = name;
this->email = email;
this->idnumber = idnumber;
};
void setName(string name) {
name = name;
}
void setEmail(string email) {
email = email;
}
void setIdnumber(int idnumber) {
idnumber = idnumber;
}
void addnewuser() {
string objectname;
cout << "Enter name of object.";
cin >> objectname;
cout << "Enter the name of the user you would like to add:";
cin >> name;
cout << "Enter the email for the user.";
cin >> email;
cout << "Enter the idnumber for the user: ";
cin >> idnumber;
LibraryUser objectname(name, email, idnumber);
}
型
我只是得到了一堆错误,我正在努力修复它,即使在人工智能的帮助下。
我尝试使用用户输入来创建一个对象,但由于这是我第一次使用头文件,我遇到了一些问题。我得到的错误是cpp文件中第五个name之前的')',然后makenewuser函数中使用的所有变量都没有得到未声明的错误,即使构造函数将它们全部删除。
1条答案
按热度按时间hgtggwj01#
在你的
.cpp
文件中,你需要提供你正在定义的函数的全限定名。例如,你的构造函数定义需要是:字符串
其他成员函数也是如此,如
型
等