#include "stdafx.h"
#include<iostream>
using namespace std;
class Base
{
public:
virtual void fun()
{
cout<<"base"<<endl;
}
};
class Der:public Base
{
public:
void fun()
{
cout<<"Der"<<endl;
}
};
void func(Base b)
{
b.fun();
}
int _tmain(int argc, _TCHAR* argv[])
{
Base b;
Der d;
b.fun();
d.fun();
func(b);
func(d);
system("pause");
return 0;
}
o/p:
base
Der
base
base
void func(Base *b)
{
b->fun();
}
int main()
{
Base b;
Der d;
b.fun();
d.fun();
func(&b);
func(&d);
system("pause");
return 0;
}
o/p:
base
Der
base
Der
can anyone please explain how virtual mechanism works fine with pointer but not with object !!
Correct me if i am wrong !
TIA