c++ – No suitable default constructor


There are two classes, the din inherits another, the public inheritance type. On compilation throws the following error: No suitable default constructor. Tell me what the problem is, two header files below.


    class Integer {
    int *_mass;
    int _system;
    int _size;
    Integer(const int *mass, const int system, const int size);
    Integer(const Integer &);
    ~Integer() {
        delete[] _mass;
        _mass = nullptr;
    Integer & operator=(const Integer &);


class IntegerCalc: public Integer {
    Integer _a;
    Integer _b;
    IntegerCalc(Integer &a, Integer &b) :
        _a(a), _b(b) {}; // ВОТ ТУТ ВЫДАЁТ ОШИБКУ
    ~IntegerCalc() {};


Your IntegerCalc class inherits from Integer – which means any IntegerCalc constructor must call the Integer constructor. Not the constructor of the field you are calling – but the constructor of the base class.

Since you don't call it – the compiler automatically adds a call to the default constructor. It turns out something like this:

    IntegerCalc(Integer &a, Integer &b) :
        Integer(), _a(a), _b(b) {};

But there is no default constructor in the base class! Hence the error.

How to fix such a mistake depends on the task. I don't understand very well what you wanted to do with your code.


The calculator subclass inherits the numbers class in order to be able to use operators and methods.

This should not be done. In order to "use operators and methods", you must use a simple friend , not inheritance. Better yet, don't make a separate interface for the calculator. Why can't the calculator use open methods?

Scroll to Top