PDA

View Full Version : copying and assignment constructors



TheKedge
17th August 2006, 13:21
Hello all,
I can guess that the following warning it's not very important but how can I avoid it?

I derive a class from some base class. The compiler tells me that the copy constructor could not be generated for the base class. I get a similar second warning about the assignment operator.

The concrete example:


class SliderWidget :public QGroupBox
{
Q_OBJECT

public:
SliderWidget(Qt::Orientation orientation = Qt::Horizontal, QWidget * parent = 0 ):QGroupBox(parent)
{
// here I call new for some widgets and do the connect stuff
}
//there is no destructor defined
};


What would a copy constructor look like? Do I call new set all the member variables in the new instance and pass it back as the copy?
An assignement operator? Do I have to so the same as in the copy constructor?
thanks
K

jacek
17th August 2006, 13:31
You can't copy QObjects.

TheKedge
17th August 2006, 13:38
Well, that's great news, actually. So, the warnings are essentially meaningless and I can't avoid them anyway, and I'm doing everything right.
Would that sum it up?
It's great being able to ignore things.
thanks for the prompt reply.
K

jacek
17th August 2006, 15:09
So, the warnings are essentially meaningless and I can't avoid them anyway, and I'm doing everything right.
Not quite, if you can't copy the base class, you can't copy the derived class too. In other words, you shouldn't implement copy constructor and assignment operator, because they won't work.