1,105,644 Community Members

Changing struct properties when used with different 2D grid array

Member Avatar
ccoder83
Newbie Poster
10 posts since Sep 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,
I'm trying to create a 2D grid that would allow me to use fluid properties in each cell of the grid, which is defined by a struct.

I have 3 grids:

Grid2D <fluidProperties> grid1;
Grid2D <fluidProperties> grid2;
Grid2D < fluidProperties> grid3;

My struct fluidProperties contains 12 different properties:

struct fluidProperties {

float foo;
float bar;
                 // ...etc.,
}

For each grid, I only want to use 6-8 of the variables contained in fluidProperties. Is there a way I can disable the use of some of the properties, depending on the type of grid I create?

For example, I may not want grid1 to be able to access

grid1.bar

Am I going about it the wrong way? Any help would be appreciated.

Member Avatar
raptr_dflo
Practically a Master Poster
604 posts since Aug 2010
Reputation Points: 48 [?]
Q&As Helped to Solve: 83 [?]
Skill Endorsements: 1 [?]
 
0
 

Since it appears that your Grid2D is a template class that you then specify by telling it what to use internally, it should be sufficient to declare the actual struct-type you need for each specific grid:

struct fluidProperties1 {
  float foo;
  float bar;
};

struct fluidProperties2 {
  float foo;
};

struct fluidProperties3 {
  float bar;
  float baz;
};

Grid2D<fluidProperties1> grid1;
Grid2D<fluidProperties2> grid2;
Grid2D<fluidProperties2> grid3;

If this isn't what you had in mind, please clarify your use case a bit more.

Member Avatar
ccoder83
Newbie Poster
10 posts since Sep 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thank you, that's an easy enough solution to my problem

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: