[solved] error: default argument missing ?



  • Hello,
    do i always need to assign all functionparametrs a default value when giving at least a single one except it's the last parameter ?

    in header

    void logIt(quint8 _level=0b11111111, QString _dir="**", QByteArray _ba=NULL);
    
    void logIt(quint8 _level, QString _dir, QByteArray _ba);
    
    void logIt(quint8 _level, QString _dir, QByteArray _ba=NULL);
    

    all the above are OK, but not :

    void lvoid logIt(quint8 _level=0b11111111, QString _dir, QByteArray _ba=NULL);
    
    void logIt(quint8 _level=0b11111111, QString _dir="**", QByteArray _ba);
    

    error: default argument missing for parameter 3 of 'void



  • The default parameters must always be the last ones., for example

    void Function( unsigned char a, unsigned char b, unsigned char c=0x20);
    

    Will work nicely, but

    void Function( unsigned char a, unsigned char b =0x20, unsigned char c);
    

    Wont compile, on your case, you can fix it easily just by changing the order in the parameters

    void logIt(QByteArray _ba, quint8 _level=0b11111111, QString _dir="**")
    


  • Yes, sure, and it makes sense, thank you


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.