Re: Can't compile this code *****SOLVED****
From: Chris Val (chrisval_at_bigpond.com.au)
Date: 11/26/04
- Next message: Chris Val: "Re: Atoi keeps on failing."
- Previous message: fb: "Re: Padding numbers"
- In reply to: Karl Heinz Buchegger: "Re: Can't compile this code *****SOLVED****"
- Next in thread: Karl Heinz Buchegger: "Re: Can't compile this code *****SOLVED****"
- Reply: Karl Heinz Buchegger: "Re: Can't compile this code *****SOLVED****"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 25 Nov 2004 19:25:51 -0800
Karl Heinz Buchegger <kbuchegg@gascad.at> wrote in message news:<41A608DB.4AD3D766@gascad.at>...
> Morten Gulbrandsen wrote:
> >
> > > On the other hand, it might be that this is indeed an exercise
> > > in pointer syntax and using pointers which eventually will lead
> > > to polymorphism. One of the standard exercises in polymorphism
> > > is to have a Cat, a Dog and a virtual MakeNoise function.
> > >
> >
> > This I don't understand, very interesting,
> > I am willing to take a close look at this.
>
> OK. A short introduction
[snipped and enjoyable read :-)]
> class Parrot : public Pet
> {
> public:
> virtual void MakeNoise() { cout << "I want a cookie\n"; }
> };
[snip]
Hehe - In Australia, our Parrot's hypothetically eat 'Crackers' :-)
> Now, your real program might contain hundreds of code sequences
> like the above, and you would be forced to update all of them
> or your program wouldn't work for the 'Parrot-case' correctly.
> Compared with the 'just add a class and implement the virtual
> function' this is much more trouble.
Just one important factor left to mention :-)
It is mandatory, that the base class implements a 'virtual'
destructor, so that when de-allocating objects created via
a base pointer and the new operator, the destructors for
each of the derived objects will be called as appropriate.
Cheers.
Chris Val
- Next message: Chris Val: "Re: Atoi keeps on failing."
- Previous message: fb: "Re: Padding numbers"
- In reply to: Karl Heinz Buchegger: "Re: Can't compile this code *****SOLVED****"
- Next in thread: Karl Heinz Buchegger: "Re: Can't compile this code *****SOLVED****"
- Reply: Karl Heinz Buchegger: "Re: Can't compile this code *****SOLVED****"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|