From: Adrien Plisson <aplisson-news@stochastique.net>
Subject: Re: how can i allocate an objekt with initialization???
Date: Mon, 06 Dec 2004 12:49:31 +0100
Date: 2004-12-06T12:49:31+01:00 [thread overview]
Message-ID: <41b44663$0$9298$ba620e4c@news.skynet.be> (raw)
In-Reply-To: <wvbry8gboi7r.fsf@sun.com>
Ole-Hjalmar Kristensen wrote:
> You are confused. You can use inheritance and virtual functions in C++
> as well without using pointers:
you are confused too... see below.
> int main(int argc, char *argv[])
> {
> b my_b(1);
> c my_c(2);
>
> test(my_b);
> test(my_c);
>
> return 0;
> }
your complete example is valid (though a little bit off-topic), but the OP was
trying to declare a variable which can hold any object from the class hierarchy
FATHER_CLASS and initialize it with a CHILD_CLASS object.
the corresponding C++ example should have been:
int main(int argc, char *argv[])
{
a &my_object = b(1);
my_object.f();
return 0;
}
note: Martin Krischik was noting that in Ada we can avoid pointers/references
to do this, unlike in C++. our 2 examples just confirm that (plus it does not
help much...).
--
rien
next prev parent reply other threads:[~2004-12-06 11:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-05 16:54 how can i allocate an objekt with initialization??? Thomas Bruns
2004-12-05 22:51 ` Stephen Leake
2004-12-06 8:52 ` Martin Krischik
2004-12-06 10:04 ` Ole-Hjalmar Kristensen
2004-12-06 11:49 ` Adrien Plisson [this message]
2004-12-06 13:34 ` Martin Krischik
2004-12-13 6:38 ` Dave Thompson
2004-12-13 11:11 ` Martin Krischik
2004-12-06 11:55 ` 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