954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Changing struct properties when used with different 2D grid array

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 wantgrid1 to be able to access

grid1.bar


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

ccoder83
Newbie Poster
10 posts since Sep 2011
Reputation Points: 10
Solved Threads: 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.

raptr_dflo
Practically a Master Poster
602 posts since Aug 2010
Reputation Points: 76
Solved Threads: 82
 

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

ccoder83
Newbie Poster
10 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: