Private members are meant to be inaccessible from outside the class. You could make username1
public and const:
#include <iostream>
#include <string>
class user1 {
public:
const std::string username1;
user1(std::string Myfirstname, std::string emailaddress, std::string); //constructor
private:
std::string email;
std::string mobile;
};
user1::user1(std::string Myfirstname, std::string emailaddress, std::string): username1(Myfirstname), email(emailaddress) {}
int main() {
user1 firstman {"John" , "[email protected]" , "011000000"};
std::cout << "Created " << firstman.username1 << " !
";
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…