From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ad988eb0a9545c86 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-04-13 04:56:06 PST Path: supernews.google.com!sn-xit-03!supernews.com!freenix!grolier!dispose.news.demon.net!demon!newspeer.clara.net!news.clara.net!news5-gui.server.ntli.net!ntli.net!news6-win.server.ntlworld.com.POSTED!not-for-mail From: "chris.danx" Newsgroups: comp.lang.ada References: <9b46dr$cd8$1@taliesin.netcom.net.uk> <9b6jtu$4is$2@taliesin.netcom.net.uk> <9b6m27$68e$1@taliesin.netcom.net.uk> Subject: Re: Problem trying to implement generics. X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: <0JBB6.10484$FD1.1197250@news6-win.server.ntlworld.com> Date: Fri, 13 Apr 2001 12:49:38 +0100 NNTP-Posting-Host: 62.252.152.168 X-Complaints-To: abuse@ntlworld.com X-Trace: news6-win.server.ntlworld.com 987162556 62.252.152.168 (Fri, 13 Apr 2001 12:49:16 BST) NNTP-Posting-Date: Fri, 13 Apr 2001 12:49:16 BST Organization: ntlworld News Service Xref: supernews.google.com comp.lang.ada:6857 Date: 2001-04-13T12:49:38+01:00 List-Id: > > > > > private > > > type Binary_Tree is new Ada.Finalization.controlled with record > > > root: Node_access := null; > > > end record; > > > > the error comes because > > > > > package body binTree is > > [snip] > > > procedure insert(insert_this : in data_type; Sort : in sort_by) is > > > New_node : Node_Access := new node; > > > current : Node_access := root; -- This is the line it compline about!! > > > > you've forgot to that Root is in Binary_Tree. > > Okay, so how do I fix it? And what is wrong, anyway? What you do is pass in a Binary_Tree type with appropriate mode. In C++ you have objects that store the methods with the data in the class. This means you don't need to refer to the object name and you can just use "root". In Ada methods are simply procedures and functions that work with objects passed in. In C++ you'd have BinTree.insert(insert_this, sort); but in Ada insert(BinTree, insert_this, sort); You use the methods with the object type. So you'd have to pass in an item of type Binary_Tree with appropriate mode and use the "root" field in this. e.g. procedure insert (BT : in out Binary_Tree; insert_this : ... sort : ...) is New_node : Node_Access := new node; current : Node_access := BT.root; -- This is what you need to do! begin ......................... ......................... end insert; If your interested i have a generic doubly linked list ADT written in Ada. It's part of the Heather modules i'm writing. I know it isn't based on tagged types(Ada objects), but it does show how to build an ADT. Your implementation of Binary_Tree is "Limited controlled" which means it's a tagged type, but i haven't added this property to it yet. I may soon, or at least make it controlled. It really doesn't matter that much since it's just an example. I will put it up on my site if you let me know you want it. > > > I have a question. From your code it doesn't look like an ADT. Is this > > what you intended? I can't remember the term for what this looks like, > but > > I think it's to do with storing the Tree as a global variable in the > package > > not as an ADT. > > Okay, major cocept problem here. > I'm coming here with C/C++ background, and I understand that Ada has a > different OO paradigm. > I assumed that for each Binary_Tree spesific type that I create, there would > be its own Root. > I mean: > package Int_BinTree is new Binary_Tree(data_type=> > Integer,Sort_by=>Integer); > > Bin_Tree_First, Bin_Tree_Second : Int_BinTree; > > Does Bin_Tree_First.Root = Bin_Tree_Second.Root ? > > > > If you want an ADT you need to pass in a Binary_Tree type as necessary. I > > didn't see it any where in your code so i'm assuming it's based on a > global > > variable. > > I think that you are talking about ADO vs ADT , right? > generic abstract data type & generic abstract data object Yes, that's it. ADO -- i must remember that! > > There's nothing wrong doing it this way! > > Then why doesn't it compile? It doesn't compile because Ada's OO is based on extensible records. You have to pass the record in even though it's an Object. In C++ the object methods are held inside the class which means they have access to the variables inside. This is not the same as Ada. Maybe, this is a better explanation, it's just like C records. Just pass in the record and use it as you wish. Remember to get the correct mode, and use the record like you would in C. There's more to Ada's OO but you don't need it for your Binary_Tree and I'm still learning about it myself. Regards, Chris Campbell