We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,473 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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

grid1.bar

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

2
Contributors
2
Replies
1 Week
Discussion Span
1 Year Ago
Last Updated
3
Views
ccoder83
Newbie Poster
10 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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
605 posts since Aug 2010
Reputation Points: 76
Solved Threads: 83
Skill Endorsements: 1

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
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0650 seconds using 2.66MB