/* -*- C++ -*- */ /************************************************************************* * Copyright(c) 1995~2005 Masaharu Goto (root-cint@cern.ch) * * For the licensing terms see the file COPYING * ************************************************************************/ // simple template test #ifdef __hpux #include #else #include using namespace std; #endif #include #include #include // Simple template test template class A { public: T a; T *p; A *next; A() { a = 111; next=NULL; } void disp() { cout << "a=" << a << "\n"; } }; A a; void test1() { cout << "test1\n"; A b; #ifdef NEVER printf("sizeof(a)=%d\n",sizeof(a)); printf("sizeof(b)=%d\n",sizeof(b)); printf("sizeof(A)=%d\n",sizeof(A)); printf("sizeof(A)=%d\n",sizeof(A)); printf("offsetof(A,next)=%d\n",offsetof(A,next)); #endif a.disp(); b.disp(); } // template with multiple argument and constant argument template class B { public: T t[SZ]; E e[SZ]; B(T os=0) { int i; for(i=0;i b; #ifdef NEVER printf("sizeof(b)=%d\n",sizeof(b)); #endif b.disp(); #ifdef NEVER printf("sizeof(B)=%d\n",sizeof(B)); printf("sizeof(B)=%d\n",sizeof(B)); #endif B c(10); #ifdef NEVER printf("sizeof(c)=%d\n",sizeof(c)); printf("offsetof(B,e)=%d\n",offsetof(B,e)); #endif c.disp(); cout << "casting test\n"; void *p; p = &c; ((B*)p)->disp(); } // Inheritance and template class C : B { int c; public: C(short os=0); void display(); }; C::C(short os) : B(os) { c=os; } void C::display() { disp(); } #ifdef NEVER void sub(int i) { cout << "sub(" << i << ")\n"; B d(50*i); d.disp(); } #endif void test3() { cout << "test3\n"; C c(20); c.display(); B d=B(100); // B d(100); d.disp(); #ifdef NEVER int i; for(i=2;i<5;i++) sub(i); #endif } // typedef test typedef B bdouble3; void test4() { cout << "test4\n"; bdouble3 e(1.5); e.disp(); } void test5() { cout << "test5\n"; B *p=new B(0.2); p->disp(); delete p; } int main() { test1(); test2(); test3(); test4(); //test5(); // not supported yet return 0; }