oop tutorials
Simen Kjaeraas
simen.kjaras at gmail.com
Tue Mar 4 10:52:51 PST 2008
On Tue, 04 Mar 2008 17:38:31 +0100, Saaa <empty at needmail.com> wrote:
>> Could anybody give a simple example of unallocated class reference use?
>> I think that would explain it all to me :)
>
> Class className; // This will create a reference
> className=new Class(); // This will allocate an instance of Class
>
> Why do I need to name the class twice?
> Is there a shortcut?
Class className = new Class();
should work, as should
auto className = new Class();
>
> And, could I do:
>
> Class className;
> className=new Class_2();
Depending on whether or not Class_2 is inherited from Class, this might
work.
i.e, this works
class Foo{}
class Bar : Foo{}
Foo f = new Bar();
And this does not:
class FooBar{}
class BarFoo{}
FooBar f = new BarFoo();
> I know some of my questions might be interpreted as being rhetorical,
> when
> they really aren't.
> I am that unknowing :)
Hey, we all started out knowing nothing. :p
-- Simen
More information about the Digitalmars-d-learn
mailing list