On Thursday 15 May 2003 00:04, Filippos Papadopoulos wrote:
/******** myListViewItem.h ******/ #ifndef MY_LIST_VIEW_ITEM_H #define MY_LIST_VIEW_ITEM_H
#include
#include #include <string> #include <iostream> class myListViewItem : public QListViewItem { public: myListViewItem(QListView * parent, QString, QString ,QString , QString , QString , QString , QString , QString );
This is where the default arguments should go: myListViewItem( QListView * parent, QString s1, QString s3 = QString::null, QString s4 = QString::null, QString s5 = QString::null, QString s6 = QString::null, QString s7 = QString::null, QString s8 = QString::null, QString s9 = QString::null ) In the .h file, not in the .cpp file! BTW it might be a good idea to use 'const QString &' here everywhere. It saves a lot of overhead avoiding to create temporary objects just for calling this function.
myListViewItem(myListViewItem * parent, QString, QString ,QString , QString , QString , QString , QString , QString );
myListViewItem(myListViewItem * parent );
You wouldn't need that one at all if you'd specify a default argument for s1 as well. In that case, a call to 'myListViewItem( myListViewItem *)' without anything else would expand to 'myListViewItem( myListViewItem *, QString::null, QString::null, ...)'.
/******** myListViewItem.cpp ******/
#include "myListViewItem.h"
myListViewItem::myListViewItem( QListView * parent, QString s1, QString s3 = QString::null, QString s4 = QString::null, QString s5 = QString::null, QString s6 = QString::null, QString s7 = QString::null, QString s8 = QString::null, QString s9 = QString::null
Wrong place for specifying default arguments (= QString::null) ! Doesn't the compiler complain about that? Those default args should go to the function declaration (the .h file), not the function definition (the .cpp file)! I am not absolutely sure, but I think the default arguments here are simply ignored.
)
:QListViewItem(parent, s1)
Make sure you pass s2, s3, s4 etc. to the parent constuctor - otherwise having s2, s3, s4 etc. here wouldn't make too much sense.
So i do the following in another source file:
myListViewItem* itemChild; vector <QString> neededLibVector; new myListViewItem(itemChild, neededLibVector[i].ascii());
so the compiler says :
no matching function for call to `myListViewItem::myListViewItem(myListViewItem*&, const char*)' myListViewItem.h:11: candidates are: myListViewItem::myListViewItem(const myListViewItem&) myListViewItem.h:22: myListViewItem::myListViewItem(myListViewItem*) myListViewItem.h:20: myListViewItem::myListViewItem(myListViewItem*, QString, QString, QString, QString, QString, QString, QString, QString) myListViewItem.h:16: myListViewItem::myListViewItem(QListView*, QString, QString, QString, QString, QString, QString, QString, QString)
...and he is perfectly right: Having specified the default args in the function definition (the .cpp file) rather in the function declaration (the .h file), you don't have a function that could be called with one myListViewItem pointer and one QString. Your default args in the function declaration are ignored, any so you only have a version with a myListViewItem pointer and a lot of QString arguments - and all the others that don't match at all here.
The point is that when i do :
QListViewItem* itemChild; vector <QString> neededLibVector; new QListViewItem(itemChild, neededLibVector[i].ascii());
the compiler is happy about it ...
Sure, because the TrollTech folks did it right and put the default args where
they belong... ;-)
BTW beware about QString::ascii() that you seem to be using here -- it tends
to make a bad mess about internationalized messages. That may be good enough
for our friends in the USA (where everything is perfect as long as 7-bit
ASCII works, the currency is $ and the time zone defaults to Pacific Time),
but for us "old Europeans" things are not so easy... tried using that in your
native Greek? Does it still work then? ;-)
CU
--
Stefan Hundhammer