I am becoming silly about this problem.
I can't seem to be able to get an inheritance past the second step of inheritance.
I need Person->Student->Vip inheritance, but somehow it stops responding to inheritance between Student and Vip.
the error is:No matching function STUD::STUD(); in the Vip::Vip() constructor
main.cpp
Code:
int main() {
Person empl("BILLY", "HOME");
STUD student("BOBBY", "OUTSIDE", 18);
Vip VIPPER("Lisa", "OFFICE", 45);
std::cout << "Navn: " << empl.HentNavn() << std::endl;
std::cout << "Adresse: " << empl.HentAdresse() << std::endl;
std::cout << "Navn: " << student.HentNavn() << std::endl;
std::cout << "Alder: " << student.HentAlder() << std::endl;
std::cout << "Navn: " << VIPPER.HentNavn() << std::endl;
std::cout << "Alder: " << VIPPER.HentAlder() << std::endl;
std::cout << "Løn: " << VIPPER.HentLoen() << std::endl;
return 0;
}
functions.cpp:
Code:
#include <iostream>
#include "person.h"
#include "stud.h"
#include "vip.h"
Person::Person(std::string Navn, std::string Adresse)
{
itsNavn = Navn;
itsAdresse = Adresse;
}
std::string Person::HentNavn() const { return itsNavn; }
std::string Person::HentAdresse() const { return itsAdresse; }
Person::~Person()
{
std::cout << "destructor Person called... \n";
}
STUD::STUD(
std::string Navn, std::string Adresse, int Alder):
Person(Navn, Adresse), itsAlder(Alder)
{
std::cout << "STUD constructor...\n";
}
int STUD::HentAlder() const { return itsAlder; }
STUD::~STUD()
{
std::cout << "destructor STUD called...\n";
}
//the error is:No matching function STUD::STUD();
Vip::Vip(std::string Navn, std::string Adresse, int Loen):
Person(Navn, Adresse)
{
itsLoen = Loen;
std::cout << "Vip constructor...\n";
}
int Vip::HentLoen() const {return itsLoen; }
Vip::~Vip()
{
std::cout << "destructor Vip called...\n";
}
person.h:
Code:
#ifndef PERSON_H_
#define PERSON_H_
class Person {
public:
Person(std::string Navn, std::string Adresse);
std::string virtual HentNavn() const;
std::string virtual HentAdresse() const;
~Person();
protected:
std::string itsNavn;
std::string itsAdresse;
};
#endif /* PERSON_H_ */
stud.h
Code:
#ifndef STUD_H_
#define STUD_H_
#include "person.h"
class STUD : public virtual Person {
public:
STUD(std::string Navn, std::string Adresse, int Alder);
int virtual HentAlder() const;
~STUD();
protected:
int itsAlder;
};
#endif /* STUD_H_ */
vip.h
Code:
#ifndef VIP_H_
#define VIP_H_
#include "stud.h"
class Vip : public STUD {
public:
Vip(std::string Navn, std::string Adresse, int Loen);
int HentLoen() const;
~Vip();
protected:
int itsLoen;
};
#endif /* VIP_H_ */