namu
namu

Reputation: 146

call a member of a nested structure, ERROR does not have class type

In main.C I am trying to access a nested structure member (g.Fp1.d_status) and am getting the error:

'g.GridPt::Fp1' does not have class type

Below is my code. I can realy use some help. Thanks. I tried stuff like g.MarchingDirection::Fp1.d_status, g.&MarchingDirection::Fp1.d_status, ... with no luck.


//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){}

Upvotes: 1

Views: 234

Answers (1)

billz
billz

Reputation: 45410

You declared Fp1, Fm1 functions inside GridPt struct, they are not members

You could change to:

struct GridPt
{   
    GridPt();   

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

Initialize all your struct members shown as below:

GridPt::GridPt() 
: d_x(0.0), 
  d_y(0.0), 
  Fp1(1.0),
  Fm1(-1.0),
  d_lstDistFn(0.0)
{}

Upvotes: 1

Related Questions