2.2.  Class Definitions

[ fromfile: classes.xml id: definingclasses ]

class ClassName {
    public:
         publicMembers 
    private:
         privateMembers 
};

Header Files

Example 2.3. src/classes/fraction/fraction.h

#ifndef _FRACTION_H_ 
#define _FRACTION_H_  

#include <QString>


class Fraction {
public:
    void set(int numerator, int denominator);
    double toDouble() const;
    QString toString() const;
private:
    int m_Numerator;
    int m_Denominator;
};

#endif


Example 2.4. src/classes/fraction/fraction.cpp

#include <QString>
#include "fraction.h"


void Fraction::set(int nn, int nd) {
    m_Numerator = nn;
    m_Denominator = nd;
}

double Fraction::toDouble() const {
    return 1.0 * m_Numerator / m_Denominator;
}

QString Fraction::toString() const {
  return QString("%1 / %2").arg(m_Numerator).arg(m_Denominator);
}