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-Thread: a07f3367d7,26a21b9e317dc639 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.180.74.74 with SMTP id r10mr370183wiv.3.1353554832226; Wed, 21 Nov 2012 19:27:12 -0800 (PST) Path: q13ni13045wii.0!nntp.google.com!feeder2.cambriumusenet.nl!feed.tweaknews.nl!94.232.116.12.MISMATCH!border-2.ams.xsnews.nl!multikabel.net!newsfeed20.multikabel.net!feed.xsnews.nl!border-1.ams.xsnews.nl!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!rt.uk.eu.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Brian Drummond Newsgroups: comp.lang.ada Subject: Re: Access type to member procedure of instance (Object Oriented programming in Ada) Date: Mon, 19 Nov 2012 11:39:03 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <9b0bcb37-8ae3-440f-af4f-a796702e4250@googlegroups.com> Mime-Version: 1.0 Injection-Date: Mon, 19 Nov 2012 11:39:03 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="dfff62e1e537b55df42008571c03e0fe"; logging-data="29707"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX196f1A2WuPdFCPHgUTw34L++GLwhc5dfN0=" User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Cancel-Lock: sha1:iUv9VaF9cHkyMJUj/YTnKgB9qkk= Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Date: 2012-11-19T11:39:03+00:00 List-Id: On Mon, 19 Nov 2012 01:59:42 -0800, ake.ragnar.dahlgren wrote: > Not sure if this has already been discussed but: Is it possible to > define a pointer to a member procedure of an instance? Yes. with Some_Package; procedure Main is Message : Some_Package.Message_Type; Method_Ref : access procedure (Message : Some_Package.Message_Type) := Some_Package.Print'Access; begin Method_Ref.all(Message); end Main; However this is not the same question as: > Is it possible to create a parameterless access type to the > Message.Print procedure? The following application refuses to compile: Message.Print is not parameterless, it is identical to Print(Message) so ... no. (This is not specifically Ada, in any OO language I have ever seen, the receiver is always the first parameter. I don't know of any language that replicates every method for every instance of a class, but I suppose it's theoretically possible!. Unless "Message" is a singleton, it would be horribly inefficient) You can certainly define a pointer to the member procedure, but it still expects a parameter, and you still have to supply that. You can certainly wrap it in a parameterless procedure (binding Message to Print) and create a parameterless access to that... with Some_Package; procedure Main is Message : Some_Package.Message_Type; procedure PrintMessage is begin Message.Print; end PrintMessage; Method_Ref : access procedure := PrintMessage'Access; begin Method_Ref.all; end Main; but I have a feeling you are trying to accomplish something else here and I can't see what. Hopefully someone else has a better idea... - Brian