class

#include<iostream>
using namespace std;
class a
{
public:
virtual void add(int)=0;
virtual void dis()=0;
};
class b:public a
{
int m;
public:
void add(int r)
{
cout<<"enter value";
m=r;
}
void dis()
{
cout<<m;
}
};

int main()
{
a *p;
b e[2];
p=&e[0];
p->add(1);
p++;
p->add(2);
p->dis();
p=&e[0];
p->dis();
return 0;
}
// when i run this code its showing me that
//Process terminated with status 255 (0 minute(s), 45 second(s))
// can any one know whats going on?
...can any one know whats going on?

Yes, and although it admittedly took me second it's actually quite simple; sizeof(a) != sizeof(b). You're much better off using the square bracket operator to move base class pointers around like this.
Topic archived. No new replies allowed.