joshua blumenkopf
joshua blumenkopf

Reputation: 1

C++ compilation error "expected constructor, destructor, or type conversion before ‘class’"

I received this error when compiling a large program parts of which I had changed, but it showed up in a part I hadn't changed. I was using gcc on unix. I've seen discussion online about similar errors, but those involve templates, which I'm not using. Also constructors should appear inside of a class not before it. Here is the part which gave the error:

#ifndef   __GRIDG_H
#define   __GRIDG_H

#include "part1g.h"

 //=================== GridParams Class
 // class for specifying the computational grid

 class GridParams :public ParameterGroup
 {IntParameter J;
 IntParameter K;
 ScalarParameter x1s;
 ScalarParameter x1f;
 ScalarParameter n1;
 ScalarParameter x2s;
 ScalarParameter x2f;
 ScalarParameter n2;
 StringParameter dx1;
 StringParameter dx2;
 IntParameter PeriodicFlagX1;
 IntParameter PeriodicFlagX2;
 IntParameter Geometry;  //  which geometry, RZ, XY, or even R-Theta

// storage used by GUI
protected:
Vector2** X;

public:
      GridParams();

  ~GridParams();

int getJ() {return J.getValue();}
int getK() {return K.getValue();}

 int getPeriodicFlagX1() {return PeriodicFlagX1.getValue();}
 int getPeriodicFlagX2() {return PeriodicFlagX2.getValue();}

  Scalar getX1s() {return x1s.getValue();}
      Scalar getX1f() {return x1f.getValue();}
  Scalar getX2s() {return x2s.getValue();}
  Scalar getX2f() {return x2f.getValue();}

  Scalar mapping_function(Scalar x, Scalar x1, Scalar x2, Scalar n);

  Grid* CreateCounterPart();
 #ifdef MPI_VERSION
       Grid* CreateCounterPart(const ostring &MPIpartition);
  #endif /*MPI_VERSION */
  public:
    /**
     * Due to problems with conversion from double to float and back to double
     * in the process of initializing the cell vertices when OOPIC is run in 
     * parallel, I'm changing the signature of the 
     * Vector2** createCellVertices(); member function to make sure that the
     * same deltaX is used in each region. The new signature has the beginning
     * of the region's x1 coordinates and the deltaX1. The latter
     * will be calculated in the same way on all processes. All arguments 
     * become of type Scalar as well for consistent handling of the float
     * and double types.
     * dad, Fri May  3 2002.
     */ 
     /*
      * Removed all hard-coded floats from the code, so conversion from
      * double to float to double should no longer happen. RT, 2003/12/09    

   */
Vector2** createCellVertices(Scalar x1min, Scalar deltaX1);
Vector2** getCellVertices();
    void deleteCellVertices();
 };



#endif  //  __GRIDG_H

and here is part1g.h

  //part1.h

 #ifndef   __PART1G_H
 #define   __PART1G_H

#include "param.h"
 class Evaluator;
//=================== ParameterGroup Class
 // Abstract base class for conceptual groups of parameters

  class ParameterGroup :public BaseParameter
 {protected:

  oopicList<BaseParameter> parameterList;
  oopicList<RuleBase> RuleList;
  oopicList<ParameterGroup> parameterGroupList;
  //  list of rules constraining parameters in the group

 public:
  ostring name; // name of group
  ostring errorMessages;
  // contains errors in input (not an integer or not a scalar)
  BOOL legal;
  oopicList<ostring> ruleMessages;

  int LegalParamName(ostring pname) {
     // search the parameterList for this name 
    int ans=0;
    oopicListIter<BaseParameter> plistI(parameterList);
    for(plistI.restart();!plistI.Done();plistI++) 
      ans|=plistI.current()->getName() == pname;
    return ans;
  }

  ParameterGroup * LookupGroupByName(ostring pname); 


  //  contains messages due to rule firings

 public:
  ParameterGroup() : BaseParameter() {};

  virtual ~ParameterGroup() {};

  virtual void setValues(oopicList<ostring> &ostringList);
  // Set the values of the parameters in the group from a list
  // of ostrings of the form   ostring("name value")

  oopicList<BaseParameter>* getParameterList();
  // Return list of parameters in group

BaseParameter* getParameter(ostring name);
  // Return a sub-parameter by name

  ostring GetName() {return name;};
  void setName(ostring _name) {name = _name;};

  void addLimitRule(ostring _name, ostring _op,
                          double _val, ostring _reason, int 
_intrinsic);

  ostring addRule(std::ifstream &fin);
  // Add a Rule to known rules via a stream

  void addRelationRule(ostring _name1, ostring _op, ostring _name2,
             ostring _reason, int   _intrinsic);

  void addAlgebraRule(ostring _name1, ostring _op1, ostring _name2,
     ostring _op2, double _val, ostring _reason, int _intrinsic);

  virtual void checkRules();
  //  Fire all applicable rules and accumulate results into Messages.

  void showRules();
  //  Diagnostic -- show all rules known by group

  void showRuleMessages();
  //  Diagnostic -- show results of all rule violations

  void showValues();
  //  Diagnostic  -- show names and values of all parameters in group

  void describe();

  virtual void writeOutputFile(std::ofstream &fout);
  //  writes to file

  virtual ostring InitializeFromStream(std::ifstream &fin);
  //  initializes parametergroup from stream

ostring getName();

virtual oopicList<ostring>* getErrorMessages()

{ return ruleMessages.isEmpty()
   ?(oopicList<ostring>* NULL:&ruleMessages; }

virtual ostring getDescription()
    { return getName(); };


private:

  ostring parseStringList(oopicList<ostring> &ostringList);
  // Support function for setValues

  ostring parseName(ostring str);
  // Support function for parseStringList

  ostring parseValue(ostring str);
  // Support function for parseStringList
};



#endif  //  __PART1G_H

Upvotes: 0

Views: 4115

Answers (1)

Mike DeSimone
Mike DeSimone

Reputation: 42805

When the compiler says there is an error before some grammar element (the class keyword, in this case), look at whatever is before that. I'm betting you're missing a } or ; at the end of part1g.h.

EDIT: Looking at part1g.h, some minor things:

  • Remove semicolon after ParameterGroup() : BaseParameter() {}
  • Remove semicolon after virtual ~ParameterGroup() {}
  • Remove semicolon after ostring GetName() {return name;}
  • Remove semicolon after void setName(ostring _name) {name = _name;}
  • Remove semicolon after virtual ostring getDescription() { return getName(); }

Not seeing exactly what's wrong, though. What is the exact error message, and what file and line does it report for the error location?

Upvotes: 4

Related Questions