Mail Archives: djgpp/1996/10/23/04:08:32
RI> Just for starters. Welcome to 'C'. Have fun!
Where is welcome to 'C++' ? ;-)
An example when, virtual functions doesn't work :
class Dummy {
protected :
int SomeData;
void Copy(Dummy *p)
{
memcpy(this,p,sizeof(Dummy));
}
public :
Dummy() {};
Dummy(Dummy *p) { Copy(p); }; // copy constructor
virtual f() { printf("This is dummy!\n"); };
}
class Dummy2 : public Dummy {
public :
Dummy2() {};
Dummy2(Dummy *p) { Copy(p); }; //copy constructor
virtual f() { printf("This is dummy2!\n"); };
};
void main()
{
Dummy *p1=new Dummy();
p1->f(); // prints "This is dummy!"
Dummy *p2=new Dummy2(p1);
p2->f(); // also prints "This is dummy!"
};
Have fun with C++ too ! ;))
======================================================================
Institute of Semiconductors Physics Ilya P. Ryzhenkov
Russian Academy of Sciencies e-mail: ilya AT spy DOT isp DOT nsc DOT ru
Siberian Branch http://spy.isp.nsc.ru
- Raw text -