c++ - 错误 : no matching function for call to 'b::b()'

标签 c++

您好,我刚开始用 C++ 编程,但我遇到了问题。我尝试在其他类(class)中创建一个类(class),但它不起作用...请帮帮我好吗?

这是我的主要内容:

#include <iostream>
#include "a.hpp"
#include "b.hpp"

using namespace std;



int main()
{

return 0;
}

这是我的第一个 cpp 类:

#include <iostream>
#include "a.hpp"

using namespace std;

a::a(){} /* The problem is here :error: no matching function for call  
to 'b::b()*/
a::~a(){}

void a::write()
{

cout << "Write a number : " << endl;
cin >> m_number;
}

这是 hpp :

#ifndef A_HPP_INCLUDED
#define A_HPP_INCLUDED

#include "b.hpp"


class a : public b
{
public:
a();
~a();
void write();

protected:
int m_number;
};


#endif // INTERFACE_HPP_INCLUDED

b类cpp:

#include <iostream>
#include "b.hpp"


using namespace std;
b::b(double c, double d){m_c = c; m_d = d}
b::~b(){}

void b::write1()
{
cout << m_c+m_d<< endl;
}

和 hpp :

#ifndef B_HPP_INCLUDED
#define B_HPP_INCLUDED


class b
{
public:
b(double c, double d);
~b();


void writed1();

protected:
double m_c;
double m_d;
};


#endif // B_HPP_INCLUDED

非常感谢您的帮助!!!

最佳答案

b 的唯一构造函数采用两个 double 参数。

a 派生自 b,但类 a 无法使用其两个必需参数调用其父类(super class)的构造函数,并且其父类(super class), b 类,没有默认构造函数。

如果您的类的构造函数具有必需的参数,而该类没有默认构造函数,并且您从该类派生,则派生类负责构造其父类(super class),并使用必需的参数调用其构造函数。

关于c++ - 错误 : no matching function for call to 'b::b()' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35590933/

相关文章:

c++ - 模板类中的双嵌套类前向声明

c++ - 我应该如何构造相互依赖的C++成员?

c++ - 从用户输入填充二维数组

c++ - 使用两个不同 LMDB 的多标签

c++ - 如何从多线程应用程序中的断言失败中优雅退出

c++ - GCC 但不是 Clang 更改函数类型的引用限定符以指向限定成员函数的指针

c++ - 如何使用两个构造函数?

c++ - 对齐外部常量 (gcc)

c++ - 错误 : expected constructor, 析构函数,或 ‘&’ token 之前的类型转换

c++ - Cereal:在没有默认构造函数的情况下反序列化对象 vector