Question: I am currently coding an algorithm that involving a recursive class. In Matlab, I can put a struct inside a struct, but I wonder if I can do the same thing in C++.

For example, I have a square matrix which can be divided into 4-smaller matrices. And each small matrix will be again decomposed into 4-smaller ones. The matrix will be divided until it has the pre-defined size. As the result, I can represent a matrix under a hierarchical tree.

In order words, I can say that each matrix has its own children and properties. Can you guide me an efficient way for programming this kind of problem. As the speed is very important for the algorithm, I am still seeking for a fastest way to implement the algorithm.

Thank in advance.

Kind Regards,

Answer: 
You can use pointers. Or containers.

```
struct Matrix
{
  // some members
  Matrix* child; //version 1
  std::vector<Matrix> Children; //version 2
}

```
It can easily be done in C and C++ using pointers:

```
struct some_struct
{
    int    some_field;
    double some_other_field;

    struct some_struct *some_pointer_to_struct;
};

```

In C++ you can use normal standard container for this, if you want more than one:

```
struct some_struct
{
    int    some_field;
    double some_other_field;

    std::vector<some_struct*> collection_of_struct_pointers;
};

```

The important thing here is that you have to use pointers, as using the structure directly in itself (like `struct some_struct foo;`) doesn't work until the structure is fully defined, and it's not fully defined until the closing brace.