From: "Rego, P." <pvrego@gmail.com>
Cc: mailbox@dmitry-kazakov.de
Subject: Re: Constructors with multiple inheritance
Date: Wed, 9 Nov 2011 19:47:01 -0800 (PST)
Date: 2011-11-09T19:47:01-08:00 [thread overview]
Message-ID: <6366850.176.1320896821400.JavaMail.geo-discussion-forums@yqcm23> (raw)
In-Reply-To: <a67beyjayq17$.1rt88uc804jfv.dlg@40tude.net>
> 1. Test_Obj is null pointer.
> 2- Objects are not constructed that way.
> 3. Memory leak
> 4. Tasks component does not terminate, which will block finalization of the
> object
>
> P.S. I absolutely fail to comprehend what are you trying to do. Virtually
> every second line of the sample you posted looks wrong. May I suggest you
> to formulate what do you actually want? People here might show you right
> patterns to achieve that goal.
I'm having a big difficult in simplifying the problem, but I will try. Initially forget about the task termination, I plan to implement it as other services to run from inside other tasks which are going to communicate with each other, but for now it's just future. I also know that there's memory leak, and that the object is null.
Maybe I can explain this easier trying to use C++. Let's suppose I have a class Par_Class with an integer and a pointer to a string. I could code, for example, (please correct me if I'm doing wrong)
class Par_Class {
public:
Par_Class (int aValue, const char *aName);
private:
int theValue;
char *theName;
};
the constructor could be implemented as
Par_Class::Par_Class (int aValue, const char *aName){
theValue = aValue;
strcpy (theName, aName);
};
and finally we could instantiate this class with
Par_Class Par_Obj (23, "My object is this");
and sure this constructor method belongs to the class Par_Class and not to any other class.
In Ada 2005, this class could be coded, for example, as
--par_pkg.ads
package Par_Pkg is
type Par_Class is tagged private;
type Par_Class_Ptr is access all Par_Class;
type Integer_Ptr is access Integer;
function Construct
(P : access Par_Class; aValue : Integer; aName : Integer_Ptr)
return Par_Class_Ptr;
private
type Par_Class is tagged
record
theValue : Integer;
theName : Integer_Ptr;
end record;
end Par_Pkg;
-- par_pkg.adb
package body Par_Pkg is
function Construct
(P : access Par_Class; aValue : Integer; aName : Integer_Ptr)
return Par_Class_Ptr is
pragma Unreferenced (P);
P_Ptr : constant Par_Class_Ptr := new Par_Class;
begin
P_Ptr.theValue := aValue;
P_Ptr.theName := aName;
return P_Ptr;
end Construct;
end Par_Pkg;
and the user could call
with Par_Pkg; use Par_Pkg;
procedure Par_Main is
Par_Obj : Par_Class_Ptr;
Int_Obj : Integer_Ptr;
begin
Int_Obj := new Integer;
Int_Obj.all := 12; -- don't worry about been string or integer
Par_Obj := Par_Obj.Construct
(aValue => 23,
aName => Int_Obj);
end Par_Main;
The compiler says me that Par_Obj is null when I use Par_Obj := Par_Obj.Construct, and I know it, and agree with it, because exactly what I want to do is to initialize my object (and so the object is not null anymore), so I can access other stuffs which are not shown here. I don't want to have a Constructor without class parameter (so according to Ada 2005 Rationale it would not be a method of the class Par_Class), because it runs away from my system architecture.
So, I would like to now if there is a way, in Ada 2005, on how I can use a method-like function (using this definition of the class from AR2005, even though exist other definitions). If there's no solution for this, no problem, I use the pure Construct implementation, it's already running ok, but I prefer to use this (possibly) other implementation scheme, if I can use.
Thank you again.
next prev parent reply other threads:[~2011-11-10 3:49 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-29 19:40 Constructors with multiple inheritance Rego, P.
2011-09-29 20:20 ` Dmitry A. Kazakov
2011-09-30 3:11 ` Rego, P.
2011-09-30 7:36 ` Dmitry A. Kazakov
2011-09-30 14:04 ` Rego, P.
2011-09-30 16:29 ` Robert A Duff
2011-09-30 19:14 ` Rego, P.
2011-09-30 16:42 ` Dmitry A. Kazakov
2011-09-30 19:42 ` Rego, P.
2011-10-06 12:46 ` Julian Leyh
2011-11-09 2:24 ` Rego, P.
2011-11-09 8:39 ` Dmitry A. Kazakov
2011-11-10 3:47 ` Rego, P. [this message]
2011-11-10 7:09 ` AdaMagica
2011-11-10 7:20 ` AdaMagica
2011-11-10 8:35 ` Dmitry A. Kazakov
2011-11-12 15:16 ` Rego, P.
2011-11-12 15:30 ` Rego, P.
2011-11-12 16:28 ` Dmitry A. Kazakov
2011-11-12 17:41 ` Rego, P.
2011-11-10 8:33 ` Simon Wright
2011-11-10 9:01 ` Georg Bauhaus
2011-11-10 9:09 ` Georg Bauhaus
2011-11-10 18:16 ` Jeffrey Carter
2011-11-10 19:39 ` Dmitry A. Kazakov
2011-11-09 9:00 ` Simon Wright
2011-11-10 3:54 ` Rego, P.
2011-10-07 0:08 ` Shark8
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox