C++ (Qt)int showError(int errorCode, const std::string& fileName) { switch (errorCode) { case ErrorType::errCannotOpenFile: std::cerr << "Error: cannot open the file " << fileName.c_str() << std::endl; break;
C++ (Qt)int showError(int errorCode, const std::string& fileName = std::string());
C++ (Qt)int showError(int errorCode, const char * fileName = 0);int showError(int errorCode, const char * msg1 = 0, const char * msg2 = 0);
C++ (Qt)if (!veс.size()) { ShowError(errNoData, "not enough data"); return;} if (!veс.size()) return ShowError(errNoData, "not enough data");
C++ (Qt)enum ErrorType { errCannotOpenFile, errCannotWriteToFile, errIncorrectData, errNo}; // ... int readData(const QString & fileName, QString & data) { QFile iFile(fileName); ErrorType errorType; if (!iFile.open(QIODevice::ReadOnly)) { errorType = ErrorType::errCannotOpenFile; } else { data = iFile.readAll(); errorType ErrorType::errNo; } iFile.close(); return errorType;}
C++ (Qt)int readData(const QString & fileName, QString & data) { QFile iFile(fileName); ErrorType errorType; if (!iFile.open(QIODevice::ReadOnly)) { errorType = ErrorType::errCannotOpenFile; } else { data = iFile.readAll(); errorType ErrorType::errNo; iFile.close(); } return errorType;}
C++ (Qt)int readData(const QString & fileName, QString & data) { QFile iFile(fileName); if (!iFile.open(QIODevice::ReadOnly)) { return ErrorType::errCannotOpenFile; } else { data = iFile.readAll(); iFile.close(); return ErrorType::errNo; }}
C++ (Qt) errorType = ErrorType::errCannotOpenFile;
C++ (Qt)enum { errNone = 0, errFileOpen = -1000, errFileWrite = -1001, errDataBad = -5000, errDataNoFormat = -5001,};
C++ (Qt)/** * Коды ошибок */enum ErrorType { errNone = 0, /**< Нет ошибок */ errFileOpen = -1000, /**< Ошибка отрытия файла */ errFileWrite = -1001, /**< Ошибка записи в файл */ errDataBad = -5000 /**< Некорректные данные в файле */};
C++ (Qt)/** * A test class. A more elaborate class description. */class Test{public: /** * An enum. * More detailed enum description. */ enum TEnum { TVal1, /**< enum value TVal1. */ TVal2, /**< enum value TVal2. */ TVal3 /**< enum value TVal3. */ } *enumPtr, /**< enum pointer. Details. */ enumVar; /**< enum variable. Details. */ /** * A constructor. * A more elaborate description of the constructor. */ Test(); /** * A destructor. * A more elaborate description of the destructor. */ ~Test(); /** * a normal member taking two arguments and returning an integer value. * @param a an integer argument. * @param s a constant character pointer. * @see Test() * @see ~Test() * @see testMeToo() * @see publicVar() * @return The test results */ int testMe(int a,const char *s); /** * A pure virtual member. * @see testMe() * @param c1 the first argument. * @param c2 the second argument. */ virtual void testMeToo(char c1,char c2) = 0; /** * a public variable. * Details. */ int publicVar; /** * a function variable. * Details. */ int (*handler)(int a,int b);};
C++ (Qt)public: //! \brief Axis index enum Axis { //! Y axis left of the canvas yLeft, //! Y axis right of the canvas yRight, //! X axis below the canvas xBottom, //! X axis above the canvas xTop, //! Number of axes axisCnt };
C++ (Qt)/*! A more elaborate class description.*/class Test {public: //! An enum. /*! More detailed enum description. */ enum TEnum { TVal1, /*!< Enum value TVal1. */ TVal2, /*!< Enum value TVal2. */ TVal3 /*!< Enum value TVal3. */ } //! Enum pointer. /*! Details. */ *enumPtr, //! Enum variable. /*! Details. */ enumVar; //! A constructor. /*! A more elaborate description of the constructor. */ Test(); //! A destructor. /*! A more elaborate description of the destructor. */ ~Test(); //! A normal member taking two arguments and returning an integer value. /*! \param a an integer argument. \param s a constant character pointer. \return The test results \sa Test(), ~Test(), testMeToo() and publicVar() */ int testMe(int a, const char *s); //! A pure virtual member. /*! \sa testMe() \param c1 the first argument. \param c2 the second argument. */ virtual void testMeToo(char c1, char c2) = 0; //! A public variable. /*! Details. */ int publicVar; //! A function variable. /*! Details. */ int (*handler)(int a, int b);};
C++ (Qt)typedef int TErrCode; int DoSomething1( void ); // что оно вернет - хзTErrCode DoSomething2( void ); // ага!
C++ (Qt)void showError( int err ){} void showError( ErrorType err ){}