I understand we can't create objects of abstract class but how is the function "void prs( subt& i )" working. "subt& i" is passing by reference. But still we are passing by reference of an object of "subt" type which is an abstract class.
Here is the code:
Code:#include <iostream> #include <string> using namespace std; class subt { public: virtual char * getd() = 0; }; class sk:public subt { public: char * getd() {return ( "in 1!" ); } }; class ot:public subt { public: char * getd() {return ( "in 2!" ); } }; void prs( subt& i ) {printf( "%s\n", i.getd() );} int main() { sk s; ot o; subt& g = o; prs( s ); prs( o ); system("pause"); }




Reply With Quote