Search code examples
c++indirection

Double indirection


The problem is as follows. I have a struct:

typedef unsigned int nat;

struct intervalo_t{
    nat fin;
    nat inicio;
};

I have done the following (where inter is a dynamic array of size n with elements of type intervalo_t that is loaded):

intervalo_t** aux=new intervalo_t*[n];
for (nat i=0; i<n; i++){
    aux[i]=inter[i];
}

What I need to do now is to show the content of inter[i].fin, but I only have access to aux[i]. If they were of a primitive type (say int for example) I would do something like printf("%d", **aux), and that would be it. Is there a way of doing something like that but with the struct that's been defined above?


Solution

  • inter[i] is of type intervalo_t* so you can use (*inter[i]).fin or inter[i]->fin. Same goes for aux[i] which is also a intervalo_t*.