Interview Question 3586
Created by admin on Sat, 17/11/2012 - 13:12
Explanation:
In this program, the << operator is overloaded with ostream as argument.This enables the 'cout' to be present at the right-hand-side. Normally, 'cout'is implemented as global function, but it doesn't mean that 'cout' is not possible to be overloaded as member function.Overloading << as virtual member function becomes handy when the class in which it is overloaded is inherited, and this becomes available to be overrided. This is as opposed to global friend functions, where friend's are not inherited..
Question:
#include class fig2d { int dim1; int dim2; public: fig2d() { dim1=5; dim2=6;} virtual void operator<<(ostream & rhs); }; void fig2d::operator<<(ostream &rhs) { rhs
Language:
Answer:
5 6