I am very newbie in ADA programming language and this is the first problem I encounter with this language.
I am trying to overload operator =
but the compiler gives me this error: "there is no applicable operator "=" for private type Queue".
Hmm but I think i I wrote it well.
Take a look to the .ads:
generic
type Value is private;
type Key is private;
with function "+"(x,y:Value) return Value is <>;
package Queue is
type Rek is record
V:Value;
K:Key;
end record;
subtype Elem is Rek;
type Queue( Max: Positive ) is limited private;
procedure Add( b: in out Queue; k: in Key; v:in Value );
procedure Get( b: in Queue; k: in Key; v: out Value; found: out Boolean );
procedure Erase(m: in out Queue; k : in Key);
function "="(mleft: in Queue; mright : in Queue) return Boolean;
function Has_Key( m: Queue ; k:Key) return Boolean;
private
type Tömb is array ( Integer range <> ) of Elem;
type Queue( Max: Positive ) is record
Adatok: Tömb(1..Max);
Putter, Getter: Positive := 1;
Size: Natural := 0;
end record;
end Queue;
and then to the .adb:
function "="(mleft: in Queue; mright : in Queue) return Boolean is
l:Boolean:=false;
l2:Boolean:=false;
val2:Value;
begin
if(mleft.Size/=mright.Size) then return false;
else
for i in 1..mleft.Size loop
Get(mleft,mleft.Adatok(i).K,val2,l2);
if l2=false or mleft.Adatok(i).V/=val2 then l:=true;
end if;
exit when l=true;
end loop;
return l=false;
end if;
end "=";
And the main() calling for "=":
procedure demmo is
mer: constant Integer :=10;
package Newq is new Queue(Integer,Integer);
s1:Newq.Queue(5);
s2:Newq.Queue(5);
begin
Newq.Add(s1,1,5);
Newq.Add(s2,1,5);
if s1=s2 then PUT_LINE("Egyenloek");
else PUT_LINE("Nem egyenloek");
end if;
end demmo;