🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by A. Dain Samples Fri, 06 Nov 1992 21:33
`new' again
#446
Author: A. Dain Samples
Date: Fri, 06 Nov 1992 21:33
70 lines
2827 bytes
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)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads