-
Structure..
I have this array
Code:
int array[3][4] =
{{1,2,3},
{4,5,6},
{7,8,9},
{10,11,12}};
And and structure like this:
struct database
{
int x_pos;
int y_pos;
int type_;
int money;
int credit;
};
If I want to access item 1,2 in the array I do like this:
number_ = array[1] [2]
But since the array only can have 1 information item in it I have an problem.
I want an structure that I can access in an similar way as the array.
So, basically I want an [3] [4] array of the structure.
And I have no idea on how to do this, can you help me?
So when I for example want the information at location [1] [2] in the structure-array I could get the type_, money, credit etc from it.
-
database my_database[3][4];
Here's an example:
Code:
#include <iostream>
using namespace std;
struct database
{
int number;
double test;
};
int main()
{
database my_database[3][4]; //Declare an array of database structs
my_database[0][0].number = 10;
my_database[0][0].test = 45.32;
cout<<my_database[0][0].number<<endl;
return 0;
}