Array of Structs Example
#include
"stdafx.h"
#include
<iostream>
using
namespace std;
struct
trees
{
public:
int treeType;
void setTreeAge()
{
TreeAge = 0;
}
private:
int TreeAge;
};
int
main()
{
trees one;
trees two;
one.treeType = 1;
one.setTreeAge();
two.treeType = 2;
two.setTreeAge();
trees myForest [4][4];
for (int
row = 0; row<4; row++)
{
for (int
col = 0; col<4; col++)
{
if (row % 2 == 0)
myForest[row][col] = one;
else
myForest[row][col] = two;
}
}
cout<<"The tree type in cell 0, 1 is: "<<myForest[0][1].treeType<<endl;
return 0;
}