I wrote a basic get function that takes the elements of a struct, and copies/stores them into separate variables. I want to do the same thing, except to store an array of structs into array variables (the key thing is that I want to use the get function that I already wrote). I can easily do what I want to do without embedding my first function, but I am required to use my first function in the second, and am having some problems.
One of my errors is that there isn't a matching function call in the embedded get function that I put inside my second function (I thought that I matched up the variables correctly with my first get function (i.e. n, c, a, and x)).
Thanks for looking.
#include <iostream>
#include <cstdlib>
using namespace std;
struct ABC
{
int n;
char c;
double a[3];
};
void get( int & n, char & c, double a[3], const ABC & x )
{
n = x.n;
c = x.c;
for (int i = 0; i < 3; i++){
a[i] = x.a[i];
}
}
void get( int n[], char c[], double a[][3], const ABC x[], int elements )
{
for (int i = 0; i < elements; i++){
get(n, c, a, x);
}
}
int main()
{
ABC x = {number, m, {1, 2, 3}};
ABC xx[4] = {
{123, 'A', {1.1, 1.2, 1.3}},
{234, 'B', {2.1, 2.2, 2.3}},
{345, 'C', {3.1, 3.2, 3.3}},
{456, 'D', {4.1, 4.2, 4.3}}
};
int n;
char c;
int a[] = {};
int n1 [4] = {};
char c1 [4] = {};
double a3 [4] [3] = {};
int elements = 3;
get(n1, c1, a3, xx, elements);
return 0;
}