[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [LC++]Pure Virtual Functions and Derived Classes



That's not what the man was asking, eventhough your answer is correct as
well, but the real answer should be : yes , it's true.
The derived class must contain a definition of derived PURE virtual
function ( that's not true regarding ordinar virtual function ).

Regards,
Uri



                                                                                                                                                     
                      Shaul Karl                                                                                                                     
                      <shaulka@bezeqint.net>                 To:      Paul M Foster <paulf@quillandmouse.com>, Linux C++ List                        
                      Sent by:                               <tuxcpprogramming@lists.linux.org.au>                                                   
                      tuxcpprogramming-admin@lists.l         cc:                                                                                     
                      inux.org.au                            Subject: Re: [LC++]Pure Virtual Functions and Derived Classes                           
                                                                                                                                                     
                                                                                                                                                     
                      29/04/02 10:20                                                                                                                 
                      Please respond to                                                                                                              
                      tuxcpprogramming                                                                                                               
                                                                                                                                                     
                                                                                                                                                     



> Is is true that where you have a pure virtual function in a base class,
> your derived classes _must_ contain a definition of that virtual
> function? Sample code:
>
> class alpha
> {
> private:
>            int x;
> public:
>            alpha() {x = 0;}
>            virtual void increment();
>            virtual void decrement();
>            virtual void turn_sideways() = 0;
> };
>
> class bravo : public alpha
> {
> public:
>            void increment() { x += 1; }
>            void decrement() { x -= 1; }
>            // notice no reference to turn_sideways()
> };
>
>
>
> Paul
>


    A class containing (or inheriting) one or more pure virtual
    functions is recognized as an abstract base class by the compiler.
    An attempt to create an independent class object of an abstract
    base class results in a compile-time error.

Taken from `The C++ primer', 3rd edition, page 927.
--

    Shaul Karl
    email: shaulka(replace with the at - @ - character)bezeqint.net



_______________________________________________
This is the Linux C++ Programming List
: http://lists.linux.org.au/listinfo/tuxcpprogramming List