2011-07-29 136 views
0

编译大型程序时,我收到了这个错误,但是它出现在我没有改变的部分。我在unix上使用gcc。我在网上看到过有关类似错误的讨论,但那些涉及模板,我没有使用。另外构造函数应该出现在不在它之前的类中。下面是这给了错误的部分:C++编译错误“期望的构造函数,析构函数或在'class'之前的类型转换”

#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 

,这里是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 
+1

真正的问题在'part1g.h'中。告诉我们。 –

回答

4

当编译器说,有一些语法元素之前的错误(class关键字,在这种情况下) ,看看之前的情况。我打赌你在part1g.h的末尾丢失了};

编辑:看着part1g.h,一些细微的东西:

  • 删除分号后ParameterGroup() : BaseParameter() {}删除分号后
  • virtual ~ParameterGroup() {}
  • 删除分号后ostring GetName() {return name;}
  • 删除分号后void setName(ostring _name) {name = _name;}
  • 删除分号后r virtual ostring getDescription() { return getName(); }

虽然没有看到确切的问题。什么是确切的错误信息,以及错误位置报告的文件和行是什么?

+0

我不是;我发布了上面的代码。 –

+0

你在'ParameterGroup * LookupGroupByName'之前。 – MSalters

+0

错误发生在'gridg.h'这个表示类的行,我分别跟踪了你的两条建议,并没有帮助@MSalters @Mike。 –

相关问题