Hello, I can't understand what compiler wants from me. I trying to create quite a big class structure with many abstract classes. Below is a part of the code with some of them. The compiler doesn't like my classes and says the he needs more constructor which I don't understand. Shouldn't he make his own default constructors? I put the copy constructors into the private part. Maybe it doesn't make much sense but even when I delete them the compiler still has a problem. I'm posting one class with and one without the copy constuctor so that you can see how it behaves in both cases.

#include<iostream>
using namespace std;
class Okno {
protected:    
    int x1,y1,x2,y2;
    string nazwa;
public:   
    int daj_x1() {return x1;}
    int daj_y1() {return y1;}
    int daj_x2() {return x2;}
    int daj_y2() {return y2;}
};

//    subclasses of Okno
class NieDesktop : public Okno{
private:
    NieDesktop(const NieDesktop&);
protected:
    Okno& ojciec;    
public:
    NieDesktop(Okno&);      
    Okno& DajOjca();      
};

NieDesktop::NieDesktop(Okno& _ojciec) : ojciec(_ojciec){}
Okno&  NieDesktop::DajOjca(){
    return ojciec;
}
//KONTROLKA
class Kontrolka : public NieDesktop{                      //abstract
    Kontrolka(const Kontrolka&);                 
};
class KontrolkaAtomowa : public Kontrolka{                      //abstract
    KontrolkaAtomowa(const KontrolkaAtomowa&);                  
};
class KontrolkaNieatomowa : public Kontrolka{                      //abstract
    //KontrolkaNieatomowa(const KontrolkaNieatomowa&);                   
};
int main(){}

Here are the compiler's messages:

30 [Warning] ` class Kontrolka' only defines private constructors and has no friends
33 [Warning] ` class KontrolkaAtomowa' only defines private constructors and has no friends
36 `Kontrolka' with only non-default constructor in class without a constructor

When you define an overloaded constructor (such as a copy constructor), the compiler no longer provides a default constructor. You will have to explicitly define a PUBLIC default constructor.

Edited 6 Years Ago by Fbody: n/a

The warnings tells a thousand words :

30 [Warning] ` class Kontrolka' only defines private constructors and has no friends 
33 [Warning] ` class KontrolkaAtomowa' only defines private constructors and has no friends 
36 `Kontrolka' with only non-default constructor in class without a constructor

Realize that in a class, if you don't specify a modifier, the function inside
of a class, the constructors, the destructures, and the member variables
are all private.

For example this class :

class Kontrolka : public NieDesktop{                      //abstract
    Kontrolka(const Kontrolka&);                 
};

The constructure you provided is private, because its that way by default. To solve your problem make the constructure pubilc, for this
one and you other ones.

This article has been dead for over six months. Start a new discussion instead.