Showing posts with label Virtual function. Show all posts
Showing posts with label Virtual function. Show all posts

Monday, 14 November 2011

Predict the output or error(s) for the following:

class base

{

        public:


            virtual void baseFun(){ cout<<"from base"<<endl;}


        };

class deri:public base

{

        public:


            void baseFun(){ cout<< "from derived"<<endl;}


        };

void SomeFunc(base *baseObj)

{

        baseObj->baseFun();


}

int main()

{

base baseObject;


SomeFunc(&baseObject);


deri deriObject;


SomeFunc(&deriObject);


}

Answer:

            from base


            from derived


Explanation: