PDA

View Full Version : Regarding syntax



Yayati.Ekbote
27th January 2010, 10:24
Hi!!

I haven't yet undrstood the syntax of inheritance in QT.

For example, the directory browser example code says->

1. class FileItem : public QListViewItem
2. {
3. public:
4. FileItem( QListViewItem *parent, const QString &s1, const QString &s2 )
5. : QListViewItem( parent, s1, s2 ), pix( 0 ) {}
6.
7. const QPixmap *pixmap( int i ) const;
8. void setPixmap( QPixmap *p );
9.
10. private:
11. QPixmap *pix;
12.
13. };

the lines 4 and 5, does the construtor of class FileItem inherit the constructor of class QListViewItem??. the syntax is confusing.. I think the constructors are overloaded. Or is it the way of overloading. Please guide me as i am unable to understand what lines 4 & 5 mean.

Archimedes
27th January 2010, 10:59
This is a C++ issue about constructors that every basic C++ book covers this topic.
When you call the constructor of FileItem, it will call the constructor inherited from QListViewItem passing the given arguments. Also you got the constructor for QPixmap initializing it to 0. This is what those lines are doing.

vishwajeet.dusane
27th January 2010, 11:00
Hi,


the lines 4 and 5, does the construtor of class FileItem inherit the constructor of class QListViewItem??
Clearly you have to review ur c++ basics here.



the syntax is confusing.. I think the constructors are overloaded. Or is it the way of overloading.

In c++, constructors can be overloaded.
Ex.



class TEST_CLASS_FOR_YOU
{
TEST_CLASS_FOR_YOU();
TEST_CLASS_FOR_YOU(int a);
TEST_CLASS_FOR_YOU(int a,int b);
}



for furthur please refer this link http://www.cplusplus.com/doc/tutorial/



No going back the example.


4. FileItem( QListViewItem *parent, const QString &s1, const QString &s2 )
5. : QListViewItem( parent, s1, s2 ), pix( 0 ) {}

This is defination of constructor FileItem which is derived from QListViewItem class. QListViewItem class has overloaded constructor QListViewItem( parent, s1, s2 ) which is called at initillization. this is not a defination of QListViewItem( parent, s1, s2 ) class remember.

Yayati.Ekbote
27th January 2010, 14:15
thanks for the reply.