您好,我刚开始用 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/