Page 219 - DCAP404 _Object Oriented Programming
P. 219
Object-oriented Programming
Notes };
int point: : length ( )
{
Function body
{
A virtual function cannot have a constructor member function but it can have the destructor
member function.
class point {
int x;
int y;
public:
virtual point (int xx, int yy); // constructors, error
void display ( );
int length ( );
} ;
A destructor member function does not take any argument and no return type can be specified
for it not even void.
class point {
int x;
int y;
public:
virtual _ point (int xx, int yy); //invalid
void display ( );
int length ( );
It is an error to redefine a virtual method with a change of return data type in the derived class
with the same parameter types as those of a virtual Method in the base class.
class base {
int x,y;
public:
virtual int sum (int xx, int yy ); //error
} ;
class derived: public base {
intz;
public:
virtual float sum (int xx, int yy);
};
The above declarations of two virtual functions are invalid. Even though these functions take
identical arguments note that the return data types are different.
212 LOVELY PROFESSIONAL UNIVERSITY