Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!think.com!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!cs.umn.edu!ux.acs.umn.edu!bru!bru!bmc From: bmc@mayo.edu (Bruce Cameron) Newsgroups: comp.lang.c++ Subject: Accessing base class constructors Message-ID: <1991Jun12.183837.15084@bmw.mayo.edu> Date: 12 Jun 91 18:38:37 GMT Sender: newsman@bmw.mayo.edu (USENET News manager) Organization: Biomedical Imaging Resource Lines: 128 Being a novice to C++, I do not understand why I am unable to access a base class' constructor from a derived class. I understand the syntax to be: dc::dc(dc ctor params):[bc](bc ctor params) { body of dc ctor } Yet when I try to do this with a base class that makes use of a vararg list I get a variety of syntax errors (using Sun C++2.1). Is it possible to have a base class constructor with a vararg list and derive classes from it that initialize the base class through its constructor? If not, any work arrounds for this? How are these supposed to work? Thanks for any and all help. (only error I get is line 57: syntax error) Sample code I'm trying: #include #include #include class base { private: int *b1; protected: int b2, b3; public: base (int a ...); void bar (); }; class derived : public base { private: int *d1; protected: base::b2; base::b3; int d2; public: derived (int a, int *b, int c ...); void foo (); }; base::base (int a ...) { va_list va; b2 = 3; b3 = 2; b1 = new int[b2]; for (int i = 0; i < b2; i++) b1[i] = b3; va_start (va, a); if (!(a)) return; if (!(b3 = va_arg (va, int))) return; b2 = a; delete b1; b1 = new int [b2]; for (i = 0; i < b2; i++) b1[i] = b3; } void base::bar () { for (int i = 0; i < b2; i++) cout << b1[i] << " "; } derived::derived (int a, int b):(int c ...) { d2 = a; d1 = new int [d2]; for (int i = 0; i < d2; i++) d1[i] = b; } void derived::foo() { if (d2 < b2) { for (int i = 0; i < d2; i++) if (d1[i] < b3) d1[i] = b3; } else { for (int i = 0; i < b2; i++) if (d1[i] > b3) d1[i] = b3; } for (int i = 0; i < d2; i++) cout << d1[i] << " "; } main () { base b (6,12); derived d (12,6); cout << "base class\n"; b.bar(); cout << "\n derived class \n"; d.foo(); } -- --Bruce "An eye for an eye makes the whole world blind" Ghandi ---------------------------------------------------- Bruce M. Cameron bmc@bru.mayo.edu Medical Sciences 1-14 voice: (507) 284-3288 Mayo Foundation fax: (507) 284-9623 200 1st ST SW Rochester, MN 55905 ARS -- WD9CKW ---------------------------------------------------- The views expressed are those of the author and do not reflect those of the Mayo Foundation, the Biomedical Imaging Resource or any person connected with those organizations. They don't speak for me, I don't speak for them.