1

I instanced the Ada.Containers.Vectors generic package like this:

package My_Vectors is new Ada.Containers.Vectors(
    Element_Type => My_Type, 
    Index_Type => Natural);

Say, I have a vector and a Standard.Natural value declared:

Foo_Vector: My_vectors.Vector;
Bar_Natural: Natural := 4;

If I call

Foo_Vector.Set_Length(Bar_Natural);

I get the following error

expected type "Ada.Containers.Count_Type"
found type "Standard.Natural"

Is there a way to cast Bar_Natural to be of Ada.Containers.Count_Type?

Basti Vagabond
  • 1,458
  • 1
  • 18
  • 26

1 Answers1

7

Sorry, I was too stupid to actually read all that my error said. I tried converting the Natural using:

Ada.Containers.Vectors.Count_Type(Bar_Natural)

Which makes zero sense! Reading the error, it is trivial to see that Count_Type is defined in package Ada.Containers.

The correct conversion would therefore be:

Ada.Containers.Count_Type(Bar_Natural);

Giving

Foo_Vector.Set_Length(Ada.Containers.Count_Type(Bar_Natural));
Basti Vagabond
  • 1,458
  • 1
  • 18
  • 26