Hello everybody, I'm new here. I'm new to C++ as well and have many problems that you might find silly. One of them is this code, not willing to compile:

#include<iostream>
class Okno;
class ListaOkienEl;

class ListaOkien{
    ListaOkienEl* pocz;
public:
    ListaOkien();
    ~ListaOkien();
    void DodajPocz(ListaOkienEl&);
    void UsunPocz();
    ListaOkienEl* WezPocz();
};
ListaOkien::ListaOkien(){   
    pocz=NULL;
}
class Okno {
protected:    
    int x1,y1,x2,y2;
};

//    podklasy okien
class Desktop : Okno{
private:      
    ListaOkien otwarte_okna;  
     
    Desktop(const Desktop&);                
public:
    Desktop();             
};
Desktop::Desktop(){
    otwarte_okna();
    x1=y1=0;
    x2=y2=1000000;
}

The compiler (devcpp) doesn't like the 32nd line. It says that there is no match for this call. But I gave it the ListaOkien::ListaOkien() constructor, so what is it talking about?

Edited 6 Years Ago by mmasny: n/a

What you are doing now is trying to use a functor. (overloaded () operator for that object)

Use the initialization section of the constructor to initilize the object:

Desktop::Desktop() : otwarte_okna()
{
    x1=y1=0;
    x2=y2=1000000;
}

Edited 6 Years Ago by Gonbe: n/a

Thank you! I have no idea what a functor is, but it now compiles and I'm happy with that :)

You can also simply delete the line 32, otwarte_okna gets constructed via the ListaOkien default constructor automatically.

How come? I thought that when I define my own constructor, the default constructor isn't created.

How come? I thought that when I define my own constructor, the default constructor isn't created.

The constructor you've written also happens to be a default constructor (i.e. constructor that can be invoked without arguments), and would be automatically invoked if you'd simply delete the line 32.

This question has already been answered. Start a new discussion instead.