user2746475
user2746475

Reputation: 13

"no matching function for call to : " compiler error

class Zbiornik
{
public:
    Zbiornik(int rozmiar)
    {
        int liczby[rozmiar];
    }
};

in code:

Zbiornik cyfry;
cyfry = liczby;

Can someone explain how to fix main.cpp:67:10: error: no matching function for call to 'Zbiornik::Zbiornik()' and why it's happening?

I can't figure out what am i missing, help much appreciated,

Upvotes: 0

Views: 88

Answers (3)

nos
nos

Reputation: 229108

This line:

 Zbiornik cyfry; 

calls the Zbiornik() constructor of your class.

But your class only has the Zbiornik(int rozmiar) constructor. And since you have defined a constructor, the compiler does not generate a default Zbiornik() constructor for you.

Add the constructor

Zbiornik() {}

to your class.

Upvotes: 0

Mark Ingram
Mark Ingram

Reputation: 73625

You haven't defined a default constructor (one that takes no parameters). You need to add:

Zbiornik::Zbiornik(), or alternatively, pass an integer through to the constructor.

Upvotes: 0

Jesse Good
Jesse Good

Reputation: 52365

Since you defined a user-defined constructor, the implicit default constructor is not generated for you by the compiler. The idea is that it wouldn't do the right thing if it was implicitly generated since you have a user-defined ctor. Therefore, you have to define it yourself:

Zbiornik(){...}

However, you have mutiple problems cyfry = liczby; and int liczby[rozmiar]; will not compile and I don't know what you are trying to do with those lines.

For one, rozmiar cannot be used in a constant expression.

Upvotes: 4

Related Questions