The importance of function return values

This is a real problem encountered in the development, the project function can not be that simple, difficult to locate the cause of the Crash, therefore, function as concisely as possible, standardized. 
mydialog.h
#ifndef MYDIALOG_H
#define MYDIALOG_H

#include <QDialog>

class MyDialog : public QDialog
{
    Q_OBJECT

public:
    MyDialog(QWidget *parent = nullptr);
    ~MyDialog();
    QString func(const QString &s);
};

#endif // MYDIALOG_H
 

mydialog.cpp
#include " mydialog.h " 

the MyDialog :: the MyDialog (the QWidget * parent): QDialog (parent) 
{ 
    QString S = " samp000 " ; 

    // This function has no return value sometimes, if there is no return value, the program will crash 
    QString getString = FUNC (S); 
} 

the MyDialog :: ~ the MyDialog () 
{ 

} 

QString the MyDialog :: FUNC ( const QString & S) 
{ 
    IF (s.isEmpty ()) 
    { 
        return S; 
    } 

}
 

main.cpp
#include "mydialog.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MyDialog w;
    w.show();

    return a.exec();
}
 
 
效果展示


Guess you like

Origin www.cnblogs.com/samp000/p/12375017.html