I am trying to learn and understand multiple inheritance.
I have a 'squat' class that is a child of an 'abandoned' class
Why am I getting the error message no matching function for call to Abandoned::Abandoned()
squatter.cpp|9|error: no matching function for call to 'Abandoned::Abandoned()'|
I have looked at a lot of similar posts on this website relating to this topic. They say they I must declare an object of Abandoned with the right arguments, but I am not trying to use any functions from Abandoned, I only want to link it squat for now.
I think it is something to do with my constructor but I can't work out what the problem is.
Sorry for the big wall of code but I couldn't think of a better way
Here is my squat .cpp/h
#ifndef SQUAT_H
#define SQUAT_H
#include<abandoned.h>
#include<building.h>
class Squat:public Buildings, public Abandoned
{
private:
bool isempty;
public:
Squat(bool);
virtual void display();
virtual void isoccupied(bool);
};
#endif // SQUAT_H
and .cpp
#include<iostream>
#include<squat.h>
#include<building.h>
#include<apartment.h>
#include<abandoned.h>
Squat::Squat(bool isitempty):isempty(isitempty){}
void Squat::isoccupied(bool isitempty)
{
if(isitempty=1)
{
isempty=1;
cout<<"The abandoned building is empty"<<endl;
}
else cout<<"The abandoned building is full of dirty squatters"<<endl;
}
My understanding is when I have said;
class Squat:public Buildings, public Abandoned
This has 'linked' the classes together
Below is my abandoned .cpp/h
#ifndef ABANDONED_H
#include<vector>
#include<building.h>
#define ABANDONED_H
class Abandoned:public Buildings
{
private:
int length;
std::vector<int> status;
int sum;
public:
Abandoned(int m_size, int asum);
Abandoned(bool);
virtual void getstatus(int);
virtual void display();
virtual void demolish(int);
virtual void rebuild(int);
//virtual void demolish(int);
};
#endif // ABANDONED_H
and my .cpp
#include<iostream>
#include<string>
#include<vector>
#include<apartment.h>
#include<building.h>
#include<abandoned.h>
#include<algorithm>
#include<numeric>
using namespace std;
Abandoned::Abandoned(int m_size, int asum): length(m_size), status(m_size, 0), sum(asum)
{}
void Abandoned::getstatus(int m_size)
{
status.push_back(length);
};
void Abandoned::display()
{
Buildings::display();
cout << " length of status is: "<<status.size()<<endl;
}
void Abandoned::demolish(int asum)
{
if(asum<3)
{
cout<<"The building is below the safety standards and should be demolished"<<endl;
}else{
cout<<"The building meets the safety standards and can be rebuilt"<<endl;}
}
void Abandoned::rebuild(int asum)
{
if(asum>3)
{
cout<<"The building is above the safety standards and should be rebuilt"<<endl;
}else{
cout<<"The building should be demolished"<<endl;}
}
The class Abandoned
does not have a no-arg constructor. That means that any constructor of the derived class must select a constructor to invoke from Abandoned
:
Squat::Squat(bool isitempty): Abandoned(...), isempty(isitempty){}