это мой первый вопрос здесь так что будьте добры :)код не будет наследовать, и я понятия не имею, почему
Я пишу программу, чтобы взять в имена, фамилии и номера/адреса электронной почты и должны использовать наследование для создания класса person_with_telephone
из базового класса Person
.
Я пробовал и даже приближаюсь, но всегда есть те немногие ошибки, которые появляются, и поскольку я новичок в C++, я не знаю, что они означают.
Вот код в вопросе:
class Person
{
private:
string m_FirstName, m_LastName, m_email, m_telephone;
public:
Person(const string& firstName, const string& lastName, const string telephone) :
m_FirstName(firstName), m_LastName(lastName), m_telephone(telephone)
{}
string get_name() const
{
return m_FirstName;
}
string get_surname() const
{
return m_LastName;
}
bool has_telephone_p()
{
if (m_telephone == "")
{
return false;
cout << "You have no phone number registered" << endl;
}
else
{
return true;
cout << "Your number is: " << m_telephone << endl;
}
}
string get_telephone() const
{
return m_telephone;
}
bool has_email_p()
{
}
};
class Person_with_telephone: public Person
{
private:
string m_telephone;
public:
Person(const string& telephone) : m_telephone(telephone)
{};
string set_telephone()
{
}
string get_telephone()
{
}
};
Игнорировать пустые функции-члены, те приходят позже. Любые идеи относительно того, почему я получаю ошибки:
main.cc: In constructor ‘Person_with_telephone::Person_with_telephone(const string&)’:
main.cc:59:73: error: no matching function for call to ‘Person::Person()’
Person_with_telephone(const string& telephone) : m_telephone(telephone)
^
main.cc:59:73: note: candidates are:
main.cc:13:3: note: Person::Person(const string&, const string&, std::string)
Person(const string& firstName, const string& lastName, const string telephone) :
^
main.cc:13:3: note: candidate expects 3 arguments, 0 provided
main.cc:6:7: note: Person::Person(const Person&)
class Person
^
main.cc:6:7: note: candidate expects 1 argument, 0 provided
<builtin>: recipe for target 'main' failed
make: *** [main] Error 1
Compilation exited abnormally with code 2 at Tue Dec 1 10:17:39
Спасибо за любую помощь!)
У вашего «Человека» уже есть телефон. Ваш 'Person_with_telephone' добавляет еще один телефон. Возможно, вы должны назвать его «Person_with_two_telephones»? Кроме того, конструктор 'class Person_with_telephone' должен быть назван' Person_with_telephone', а не 'Person'. –