0

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 by mmasny: n/a

3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by mitrmkar
Featured Replies
  • 1

    What you are doing now is trying to use a [URL=http://en.wikipedia.org/wiki/Function_object]functor[/URL]. (overloaded () operator for that object) Use the initialization section of the constructor to initilize the object: [CODE="C"] Desktop::Desktop() : otwarte_okna() { x1=y1=0; x2=y2=1000000; } [/CODE] Read More

1

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 by Gonbe: n/a

0

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

0

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

0

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

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.