comp.lang.ada
 help / color / mirror / Atom feed
From: "R" <ruthless@poczta.onet.pl>
Subject: Re: newbie - OOP in Ada Set and Get Methods
Date: 28 Dec 2004 09:30:55 -0800
Date: 2004-12-28T09:30:55-08:00	[thread overview]
Message-ID: <1104255055.672275.111440@z14g2000cwz.googlegroups.com> (raw)
In-Reply-To: <HjgAd.817215$8_6.265650@attbi_s04>


Jeff C r e e.m wrote:
> It is not possible for anyone to answer this question since we don't
know
> what you
> are trying to accomplish.

I'm only trying to write a constructor.
Package testclass.
testclass.Create is meant to be my constructor

given main unit:

with Text_IO;
use Text_IO;
with testclass; -- include testclass package

procedure Main is
object : testclass.rec1_Type := testclass.Create(10);
begin
Put_Line(Integer'Image(testclass.Get(object)));
end Main;

testclass specyfication:

package testclass is
type rec1 is tagged private;

type rec1_Type is access rec1;

function Create(s: Integer) return rec1_Type;
function Set(this: rec1_Type; s: Integer) return Integer;
function Get(this: rec1_Type) return Integer;

private
type rec1 is tagged record
field: Integer;
end record;
end testclass;

testclass body:

package body testclass is

function Create(s: Integer) return rec1_Type is
begin
return testclass.rec1_Type(field=>s);
end Create;

function Set(this: rec1_Type; s: Integer) return Integer is
begin
this.field := s;
return this.field;
end Set;

function Get(this: rec1_Type) return Integer is
begin
return this.field;
end Get;

end testclass;

during compilation gnatmake points an error to:

return testclass.rec1_Type(field=>s);

$ gcc -c testclass.adb
testclass.adb:5:33: invalid prefix in call
gnatmake: "testclass.adb" compilation error
(the 5th line of testclass is return statement)


and I don't know how to write this constructor to return the access
type rec1_Type to rec1
hope it helps to help me ;-)

thanks in advance

best regards
R




  reply	other threads:[~2004-12-28 17:30 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-28 12:41 newbie - OOP in Ada Set and Get Methods R
2004-12-28 13:36 ` Jeff C r e e.m
2004-12-28 16:26   ` R
2004-12-28 17:01     ` Jeff C r e e.m
2004-12-28 17:30       ` R [this message]
2004-12-28 17:20     ` Martin Dowie
2004-12-28 17:36       ` R
2004-12-28 19:47         ` Mark Lorenzen
2004-12-28 19:48         ` Adrien Plisson
2004-12-28 19:58         ` Georg Bauhaus
2004-12-28 21:17         ` Martin Dowie
2004-12-29 10:06           ` R
2004-12-29 12:33             ` Martin Dowie
2004-12-29 17:35             ` Georg Bauhaus
2004-12-29 19:12             ` Martin Krischik
2004-12-30 12:14               ` Georg Bauhaus
2004-12-29 19:11         ` Martin Krischik
2004-12-28 13:39 ` Martin Krischik
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox