I am trying to write code that takes in virtual voids and pure virtual voids. My understanding is that with a pure virtual void you do not include the function in the base class, but in the subclass. If you don't, you make the subclass abstract. Well, there's the error I am getting for the first problem. I have an override in the subclass, so I can't figure out what the problem is.
The second error I am getting is that there is no instance of constructor that matches the argument list. Please help, I have read several things, rewatched the demos 3 times. I know it has to be something simple...I just can't see it.
Both errors are in the main.cpp file at the bottom of this message.
Thanks for the help.
Here is the code:
person.h
#pragma once
#include <string>
#include <iostream>
class Person
{
private:
const std::string first_name;
const std::string last_name;
const std::string race;
const std::string sex;
int age;
protected:
long phoneNumber;
public:
Person();
Person(const std::string & first_name, const std::string & last_name, const std::string & race, const std::string & sex, int & age, long long & phoneNumber);
Person * p = new Student("Barry", "Slater", "White", "Male", 45, 6785551919, "Physics"); <error here: object of abstract class type student is not allowed: pure virtual function "Person::Outputidentity" has no overrider>
Person * t = new Teacher("Dwayne", "Wylds", "Asain", "Male", 61, 4045552323); <error here: No instance of object "Teacher::Teacher" matches the argument list. argument types are: (const char[7], const char [6], const char[6], const char[5], int, unsigned long) >
Well, there's the error I am getting for the first problem.
The problem is that you have a typo in the Student class. In the Teacher class you need to remove the scope operator Person:: in front of the Outputidentity() function.
You can use the override keyword in order to determine that the function must override:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
class Student : public Person
{
private:
std::string course;
public:
Student ();
Student(const std::string & first_name, const std::string & last_name, const std::string & race, const std::string & sex, int & age, longlong & phoneNumber, const std::string & course);
virtual std::string Outputidentitiy() override; // Will be a compiler error due to ..titiy
virtualvoid Outputage() const;
virtual ~Student();
};