(Removed original text as it is unrelated to the current question which has already been answered. See revisions.)
Here is my example test.hpp
(simplified):
class House {
private:
int nWindows;
public:
House(int nWindows);
int getNumberOfWindows();
};
class PaintedHouse : public virtual House {
private:
int colorCode;
public:
PaintedHouse(int nWindows, int colorCode);
int getColorCode();
};
class OccupiedHouse : public virtual House {
private:
int nPeople;
public:
OccupiedHouse(int nWindows, int nPeople);
int getNumberOfPeople();
};
class PaintedOccupiedHouse : public PaintedHouse, OccupiedHouse {
public:
PaintedOccupiedHouse(int nWindows, int colorCode, int nPeople);
};
And test.cpp
:
#include "test.hpp"
House::House(int nWindows) { this->nWindows = nWindows; }
int House::getNumberOfWindows() { return this->nWindows; }
PaintedHouse::PaintedHouse(int nWindows, int colorCode) : House(nWindows) {
this->colorCode = colorCode;
}
int PaintedHouse::getColorCode() { return this->colorCode; }
OccupiedHouse::OccupiedHouse(int nWindows, int nPeople) : House(nWindows) {
this->nPeople = nPeople;
}
int OccupiedHouse::getNumberOfPeople() { return this->nPeople; }
PaintedOccupiedHouse::PaintedOccupiedHouse(int nWindows, int colorCode, int nPeople)
: PaintedHouse(nWindows, colorCode), OccupiedHouse(nWindows, nPeople) {}
GCC returns:
test.cpp: In constructor ‘PaintedOccupiedHouse::PaintedOccupiedHouse(int, int, int)’:
test.cpp:18:72: error: no matching function for call to ‘House::House()’
: PaintedHouse(nWindows, colorCode), OccupiedHouse(nWindows, nPeople) {}
^
test.cpp:18:72: note: candidates are:
test.cpp:4:1: note: House::House(int)
House::House(int nWindows) { this->nWindows = nWindows; }
^
test.cpp:4:1: note: candidate expects 1 argument, 0 provided
In file included from test.cpp:2:0:
test.hpp:2:7: note: constexpr House::House(const House&)
class House {
^
test.hpp:2:7: note: candidate expects 1 argument, 0 provided
test.hpp:2:7: note: constexpr House::House(House&&)
test.hpp:2:7: note: candidate expects 1 argument, 0 provided
Could you give me any advice what I am doing wrong? Is the general concept correct?
See Question&Answers more detail:os