Use of C++ Classes

I was wondering if I could put the section at the beginning rather than at the end before the definition of the class.

const REAL    ModMisfit::DefMinDT  = 0.01;
const REAL    ModMisfit::DefSigma0 = 0.01;
const double  ModMisfit::DefDAngSh = 2;
const REAL    ModMisfit::DefKBeta  = 5;
const bool    ModMisfit::DefHW     = false;

Outline of the C++ class is in a modmis.h file as below.

class ModMisfit
{

public:

  ModMisfit() : MinDist(-1),
                MDAcc(-1),
                MaxIter(-1),
                DAngSh(DefDAngSh),
                HW(DefHW),
                Extrap(true),
                MinDT(DefMinDT),
                Sigma0(DefSigma0),
                KBeta(DefKBeta),
                Vrb(none) { }

  void SetMaxIter(
      const int  maxiter );

  void SetDAngSh(
      const double  dangsh );

  void SetdTau(
      const REAL  dtau );
protected:

  static const REAL    DefMinDT;
  static const REAL    DefSigma0;
  static const double  DefDAngSh;

  int            NPhases, NSrc, MaxIter;
  REAL    MinDist, MDAcc,  MinDT, Sigma0, KBeta;
  double    DAngSh;
  bool        HW, Extrap;
  Source    **Src;
  List<REAL>   X, T1, T2;

  void ResetSrc();

};

void ModMisfit::SetdTau(
    const REAL  dtau )
{
    for ( int i = 0; i < NSrc; i++ )
    {
        Src->SetdTau(dtau);
    }
}

// ***************************************************************************

void ModMisfit::SetIntegration(
    const Integration  intg )
{
    for ( int i = 0; i < NSrc; i++ )
    {
        Src->SetIntegration(intg);
    }
}

etc

const REAL    ModMisfit::DefMinDT  = 0.01;
const REAL    ModMisfit::DefSigma0 = 0.01;
const double  ModMisfit::DefDAngSh = 2;
const REAL    ModMisfit::DefKBeta  = 5;
const bool    ModMisfit::DefHW     = false;

You cannot define anything before it is declared. It will just complain 'no such class' or the like. Once it is declared though you can instantiate things in any order you like.

Anyway that's what headers are for. You should declare the class in the header file and instantiate functions and static values in the .cpp:

/* modmisfit.h */

/* these ifdefs prevent modmisfit.h being multiply included */
#ifndef __MODMISFIT_H__
#define __MODMISFIT_H__

class ModMisfit
{

public:

  ModMisfit() : MinDist(-1),
                MDAcc(-1),
                MaxIter(-1),
                DAngSh(DefDAngSh),
                HW(DefHW),
                Extrap(true),
                MinDT(DefMinDT),
                Sigma0(DefSigma0),
                KBeta(DefKBeta),
                Vrb(none) { }

  void SetMaxIter(
      const int  maxiter );

  void SetDAngSh(
      const double  dangsh );

  void SetdTau(
      const REAL  dtau );
protected:

  static const REAL    DefMinDT;
  static const REAL    DefSigma0;
  static const double  DefDAngSh;

  int            NPhases, NSrc, MaxIter;
  REAL    MinDist, MDAcc,  MinDT, Sigma0, KBeta;
  double    DAngSh;
  bool        HW, Extrap;
  Source    **Src;
  List<REAL>   X, T1, T2;

  void ResetSrc();

};

#endif/*__MODMISFIT_H__*/
/* modmisfit.cpp */
#include "modmisfit.h"

const REAL    ModMisfit::DefMinDT  = 0.01;
const REAL    ModMisfit::DefSigma0 = 0.01;
const double  ModMisfit::DefDAngSh = 2;
const REAL    ModMisfit::DefKBeta  = 5;
const bool    ModMisfit::DefHW     = false;

void ModMisfit::SetdTau(
    const REAL  dtau )
{
    for ( int i = 0; i < NSrc; i++ )
    {
        Src->SetdTau(dtau);
    }
}

// ***************************************************************************

void ModMisfit::SetIntegration(
    const Integration  intg )
{
    for ( int i = 0; i < NSrc; i++ )
    {
        Src->SetIntegration(intg);
    }
}

etc

...that way you can use these functions from any .cpp file by including the header file, and avoid getting multiple definition errors.

Oh yes, cannot define before the class as they are class members. But can define them before the member functions as you say.

I have the ifdef's to prevent modmisfit.h being multiply included. Has not included everything as it was quite long class.

Thanks for your help