I made this class
class Person {
public:
Person(const std::string& name, const std::string& email, const std::string& city)
: name(name), email(email), city(city) {
}
bool hasCity() const {
return city.compare("") == 0;
}
void print() const {
std::cout << name + " <" + email + ">";
if(hasCity()){
std::cout << ", " + city;
}
std::cout << std::endl;
}
bool equalTo(const Person& comparedPerson) const {
return email.compare(comparedPerson.email) != 0;
}
bool equalId(std::string comparedId){
return email.compare(comparedId) != 0;
}
const std::string name;
const std::string email;
const std::string city;
};
What is problematic for me is that when i try to create new Person with:
const Person& newPerson = (const Person &) new Person(name, email, city);
i get this error
error: invalid cast of an rvalue expression of type 'Person*' to type 'const Person&'
const Person& newPerson = (const Person &) new Person(name, email, city);
I would like why newly created Person is Person* instead of just Person.