https://github.com/root-project/root
Raw File
Tip revision: b021ae86a45df12d6cad5f1793090c8c98ac49fd authored by Rene Brun on 30 June 2009, 07:26:56 UTC
Tagging production version v5-24-00
Tip revision: b021ae8
inherit2.cxx
/* -*- C++ -*- */
/*************************************************************************
 * Copyright(c) 1995~2005  Masaharu Goto (cint@pcroot.cern.ch)
 *
 * For the licensing terms see the file COPYING
 *
 ************************************************************************/
//
// class inheritance test 2
//
// same member function name
// inheritance from header information and later bind the body
//
#ifdef __hpux
#include <iostream.h>
#else
#include <iostream>
using namespace std;
#endif


class A {
       protected:
	 int a1;
       public:
	 A(int i);
	 int A1(void);
	 void disp(void) {  cout << "a1=" << a1 << "\n"; }
 };

 class B : public A {
	 int b1;
       public:
	 int B1(void);
	 B(int i);
	 void disp(void) { cout <<"a1="<<a1<<" b1="<<b1<<"\n"; }
 };

 A::A(int i)
 {
	 a1=i;
 }

 int A::A1(void)
 {
	 return(a1);
 }

 B::B(int i)
 : A(i+1)
 {
	 b1=i;
 }

 int B::B1(void)
 {
	 return(b1);
 }

 int main()
 {
	 A Aobj=A(15);
	 B Bobj=B(3);

	 Aobj.disp();
	 Bobj.disp();

	return 0;
}
back to top