| www.delorie.com/archives/browse.cgi | search | 
| From: | Michael Schuster <schuster AT eev DOT e-technik DOT uni-erlangen DOT de> | 
| Newsgroups: | comp.os.msdos.djgpp | 
| Subject: | Re: C++ virtual definitions | 
| Date: | Thu, 15 Jul 1999 07:05:58 GMT | 
| Organization: | Regionales Rechenzentrum Erlangen, Germany | 
| Lines: | 69 | 
| Message-ID: | <19990715.7055816@schuster.eev> | 
| References: | <378CB349 DOT EFAAD8A0 AT geocities DOT com> | 
| NNTP-Posting-Host: | eev6.e-technik.uni-erlangen.de | 
| Mime-Version: | 1.0 | 
| X-Priority: | 3 (Normal) | 
| X-Newsreader: | Mozilla/3.0 (compatible; StarOffice/5.1; Win32) | 
| To: | djgpp AT delorie DOT com | 
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp | 
| X-MIME-Autoconverted: | from quoted-printable to 8bit by delorie.com id NAB10482 | 
| Reply-To: | djgpp AT delorie DOT com | 
>>>>>>>>>>>>>>>>>> Ursprüngliche Nachricht <<<<<<<<<<<<<<<<<<
Am 14.07.99, 17:56:57, schrieb Sahab Yazdani <beyonder69 AT geocities DOT com> 
zum Thema C++ virtual definitions:
> okay I have a question about the C++ class model (who doesn't), lets 
say
> I make a class that contains one or more virtual functions, and the
> class has dome properties (variables).  Later I want to make an
> inheritance class that only re-writes one of the virtual functions.  I
> tried doing this with DJGPP, but it didn't quite work out as I had
> planned and the compiler gave me errors galore about the quality of my
> code. Could someone please send me code snipets on how I do this??
Hi! 
see this below (hope it helps). Output is T1:2 (newline) T2:3
Gruesse
Michi
#include <stream.h>
class base
{ 
 public:
   int m_a;
   base(int a);
   virtual void overload ();
   virtual void func();
};
class derived:public base
{
 public:
   derived(int a);
   virtual void overload ();
};
base::base(int a){m_a=a;}
void base::overload(){m_a=2;}
void base::func(){m_a=1;}
derived::derived(int a):base(a) {}
void derived::overload(){m_a=3;}
int main()
{
   base T1(0);
   derived T2(0);
   T1.overload();
   T2.overload();
   cout<<"\nT1:"<<T1.m_a;
   cout<<"\nT2:"<<T2.m_a;
}
| webmaster | delorie software privacy | 
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |