1

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;
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
Iero
  • 134
  • 9
  • 1
    `Use Type Newq;` after instantiating the package Newq should make its primitive operations visible. Otherwise the way to access the function would be `if Newq."="(s1,s2) then ...` –  Oct 13 '14 at 20:12
  • @BrianDrummond but where to write the `use type Newq`? It gives me more errors..."subtype mask is required " – Iero Oct 13 '14 at 20:18
  • Is that the whole "main" file? If so, you're missing a "with Queue;" before "procedure demmo is" – egilhh Oct 13 '14 at 20:23
  • @egilhh no it is not the whole...i wrote that `with queue`. – Iero Oct 13 '14 at 20:25
  • The problem is sold if I use `if Newq."="(s1,s2) then ...` but if i want to `use type newq` i did not know where to write it because if i write it before `begin` i get "subtype mask is required " err. – Iero Oct 13 '14 at 20:28
  • 2
    It should be `use type newq.Queue;` just after `package newq is...;` – egilhh Oct 13 '14 at 20:29

1 Answers1

1

if you want direct visibility to a type's concrete "=" operator, you have to make it visible. For that you need either "use" or "use type" or "use all type".

package Newq is new Queue(Integer,Integer);
use type newq.Queue;

References

TamaMcGlinn
  • 2,840
  • 23
  • 34
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265