home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: gnu.g++.help
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!news.cs.indiana.edu!babbage.ece.uc.edu!dain
- From: dain@holmes.ece.uc.edu (A. Dain Samples)
- Subject: `new' again
- Message-ID: <1992Nov6.213308.24315@babbage.ece.uc.edu>
- Followup-To: gnu.g++.help
- Originator: dain@holmes.ece.uc.edu
- Sender: root@babbage.ece.uc.edu (Operator)
- Nntp-Posting-Host: holmes.ece.uc.edu
- Reply-To: Dain.Samples@uc.edu
- Organization: University of Cincinnati
- Date: Fri, 6 Nov 1992 21:33:08 GMT
- Lines: 70
-
-
- My students and I are trying to implement classes with customized
- `new' operators. Consider the following code:
-
- ================================================================
- class A {
- public:
- void * operator new(size_t, int p,uint *p2,uint *p3);
- };
-
- class B:A{
- int a;
- int b;
- public:
- B(); // **NOTE 1**
-
-
- };
-
- B::B(){} // **NOTE 2**
-
- main () {
- uint q1, *q2, *q3;
- int i;
-
- q1=sizeof(B);
- q2=(uint *)2;
- q3=(uint *)3;
-
- B *pa=new(q1,q2,q3) B;
- : // etc.
- ================================================================
-
- When we compile this with g++, we get an error message on the line
- marked **Note 2** that says ``too few parameters to new operator''.
-
- However, if we remove the lines marked **Note i** -- that is, we
- do not declare a constructor for derived class B, then the program
- works as expected! The new operator for base class A is invoked when
- we create a B.
-
- 1) Why should a constructor for B interfere with the invocation of the
- new defined in base class A?
-
- 2) Does the constructors for a derived class intercept calls on new?
-
- 3) Have I totally missed the boat here, or does g++ implement a
- totally different paradigm of constructors and `new' operators than
- Borland C++? (for which code similar to this presents no problems).
- Is this paradigm written up anywhere?
-
- Any pointers would be very much appreciated. We can't figure out what
- the compiler is expecting of us.
-
- (A general comment on the compiler implementation: ``too few
- parameters'' or ``too many parameters'' isn't really helpful as error
- messages; it would help to know how many parameters were being
- expected.)
-
- Thanks!
- --
- ========================================================================
- A. Dain Samples, Dain.Samples@uc.edu, wk:(513)556-4783, hm:(513)771-5492
- ------------------------------------------------------------------------
- It is so difficult to find the beginning. Or, better, it is difficult
- to begin at the beginning. And not try to go further back.
- -Wittgentstein (from "On Certainty")
-
- May the background be with you.
- -Heidegger (from "Being and Time", paraphrased)
-