I am trying to create a package with a singleton variable that is auto initialized. If the singleton variable is not a controlled type, then the compiler doesn't complain, but when I make it controlled, I get the warning:"cannot call Initialize before body seen"
Followed by: "Program error will be raised at run time."
So, I think the compiler wants the singleton variable to be hidden from child objects, but this is not what I want. Here's my code:
with Ada.Finalization;
package static_member is
type singleton_type is tagged limited private;
private
type singleton_type is new Ada.Finalization.Limited_Controlled with record
data_to_init: Natural;
end record;
overriding procedure Initialize(data: in out singleton_type);
overriding procedure Finalize(data: in out singleton_type);
--This is where I get the warnings.
--I want singleton to be visible to child objects.
singleton: singleton_type;
end static_member;
Then the package body is:
package body static_member is
overriding procedure Initialize(data: in out singleton_type) is
begin
data.data_to_init := 0;
end Initialize;
overriding procedure Finalize(data: in out singleton_type) is null;
end static_member;
How would I create a singleton variable that is initialized, and ready to use by the time object instances begin to be created? Thanks in advance.