没有用于调用'class'的匹配函数

时间:2017-10-27 13:25:26

标签: c++ class multiple-inheritance

我正在努力学习和理解多重继承。

我有一个'蹲'班,是一个'被遗弃'班的孩子

为什么我收到错误消息没有匹配函数来调用Abandoned :: Abandoned()

squatter.cpp | 9 |错误:没有匹配函数来调用'Abandoned :: Abandoned()'|

我查看了本网站上与此主题相关的很多类似帖子。他们说他们必须用正确的论据宣布一个被遗弃的对象,但我并没有尝试使用Abandoned中的任何函数,我只想暂时将它连接起来。

我认为这与我的构造函数有关,但我无法解决问题所在。

对不起代码的大墙,但我想不出更好的方法

这是我的深蹲.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

和.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;
}

我的理解就是我说的时候;

class Squat:public Buildings, public 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

和我的.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;}

}

1 个答案:

答案 0 :(得分:4)

Abandoned没有no-arg构造函数。这意味着派生类的任何构造函数都必须选择一个构造函数来从Abandoned

调用
Squat::Squat(bool isitempty): Abandoned(...), isempty(isitempty){}