1

在 main.CI 中,我尝试访问嵌套结构成员(g.Fp1.d_status)并收到错误消息:

'g.GridPt::Fp1' 没有类类型

下面是我的代码。我真的可以使用一些帮助。谢谢。我尝试了诸如 g.MarchingDirection::Fp1.d_status, g.&MarchingDirection::Fp1.d_status, ... 之类的东西,但没有成功。


//Filename: main.C

#include "GridPt.h"

int main()
{   
    GridPt g;

    g.d_lstDistFn;
    g.Fp1.d_status; \\ERROR: 'g.GridPt::Fp1' does not have class type

    return 0;
}

//Filename: MarchingDirection.h

#ifndef included_MarchingDirection
#define included_MarchingDirection

struct MarchingDirection
{
    MarchingDirection(double FValue);   

    double d_F;              
    int d_inOut;             
    char d_status;          
};
#endif

//Filename: MarchingDirection.C

#include "MarchingDirection.h"

MarchingDirection::MarchingDirection(double FValue)  
: d_F(FValue),
  d_inOut(static_cast<int>(FValue)),
  d_status('d'){}

//Filename: Grid2D.h

#ifndef included_GridPt
#define included_GridPt

#include "MarchingDirection.h"
#include <cstddef>

struct GridPt
{   
    GridPt();    

    double d_x, d_y; 
    MarchingDirection Fp1(double F=1.0), Fm1(double F=-1.0);
    double d_lstDistFn;    
};

#endif 

//Filename: GridPt.C

#include "GridPt.h"

GridPt::GridPt() 
: d_lstDistFn(0.0){}
4

1 回答 1

1

您在 GridPt 结构中声明了 Fp1、Fm1 函数,它们不是成员

您可以更改为:

struct GridPt
{   
    GridPt();   

    double d_x, d_y; 
    MarchingDirection Fp1, Fm1;
    double d_lstDistFn;    
};

初始化所有结构成员,如下所示:

GridPt::GridPt() 
: d_x(0.0), 
  d_y(0.0), 
  Fp1(1.0),
  Fm1(-1.0),
  d_lstDistFn(0.0)
{}
于 2012-11-22T00:14:35.813 回答